16. What are the four pillars of OOP?
Encapsulation, Abstraction, Inheritance, Polymorphism.
17. What is encapsulation?
Hiding data inside a class and exposing it via methods or properties.
18. What is abstraction?
Hiding implementation details and exposing only functionality.
19. What is inheritance?
A class can inherit fields and methods from a parent class.
20. What is polymorphism?
Ability of objects to take multiple forms. Includes compile-time (overloading) and run-time (overriding).
21. What is method overloading?
Defining multiple methods with the same name but different signatures.
22. What is method overriding?
Redefining a base class method in a derived class using virtual and override.
23. What is the difference between virtual, override, and new keywords?
virtual: method can be overriddenoverride: overrides a base class virtual methodnew: hides base class method
24. What is the difference between class and struct?
- Class: reference type, allocated on heap
- Struct: value type, allocated on stack
25. Can a struct inherit from another struct?
No. Structs cannot inherit from other structs or classes but can implement interfaces.
26. Can a class inherit from multiple classes?
No. C# supports single inheritance but allows multiple interface implementation.
27. What is an abstract class used for?
To provide a base class with shared functionality while preventing direct instantiation.
28. What is an interface?
Defines a contract that classes must implement.
29. Can an interface contain properties in C#?
Yes, with getter/setter definitions; since C# 8, it can have default implementations.
30. What is the difference between an interface and an abstract class?
- Abstract: can have fields and implemented methods
- Interface: only signatures (mostly)