.
NET C# OOP Interview Cheat Sheet
* 1. OOP Principles
- Encapsulation - Binding data and methods that work on data within one unit.
- Abstraction - Hiding internal details and showing only essential features.
- Inheritance - Deriving a class from another class to promote code reuse.
- Polymorphism - One interface, many implementations (method overloading/overriding).
* 2. Access Modifiers
- public - Accessible from anywhere.
- private - Accessible only within the same class.
- protected - Accessible within the same class and derived classes.
- internal - Accessible within the same assembly.
* 3. Constructors
- Special method invoked when object is created.
- Can be default, parameterized, static, or copy constructor.
- Example: public MyClass(string name) { this.name = name; }
* 4. Inheritance
- Base class members are reused in derived class.
- Use ':' to inherit. Example: class Dog : Animal
- Support for single inheritance only in C# (no multiple inheritance).
* 5. Polymorphism
- Method Overloading - Same method name with different parameters.
- Method Overriding - Using 'virtual' and 'override' keywords.
- Example: public override void Speak() { Console.WriteLine("Bark"); }
* 6. Abstract Classes & Interfaces
- Abstract Class - Cannot be instantiated, can have method implementation.
- Interface - Only method signatures, implemented using 'interface' keyword.
- A class can inherit multiple interfaces, but only one abstract class.
* 7. Properties
- Used to access class fields with get and set accessors.
- Example: public string Name { get; set; }
* 8. Static Keyword
- Static members belong to the class, not instances.
- Useful for utility functions or shared data.
- Example: public static int Count = 0;
* 9. Exception Handling
- try { ... } catch(Exception ex) { ... } finally { ... }
- Always handle exceptions to avoid runtime errors.
- Use custom exceptions when needed.
* 10. Object and Class
- Class - Blueprint for creating objects.
- Object - Instance of a class.
- Use 'new' keyword to create an object: var car = new Car();