What are the important pillars of OOPs ? Explain it. | Encapsulation: Bundling data and methods that operate on the data within a class, hiding the internal state of objects.
Abstraction: Hiding complex implementation details and showing only the essential features of an object.
Inheritance: Allowing a class to inherit properties and methods from another class, promoting code reuse.
Polymorphism: Enabling objects to be treated as instances of their parent class, allowing a single function to behave differently based on the object type. |
Abstraction vs Encapsulation? | Abstraction focuses on hiding the complex implementation and showing only the necessary parts of the object.
Encapsulation is about bundling the data and methods that work on the data within one unit and restricting access to some of the object's components |
Explain static vs dynamic polymorphism ? | Static Polymorphism (Compile-time): Achieved through method overloading or operator overloading; the method to be executed is determined at compile time.
Dynamic Polymorphism (Run-time): Achieved through method overriding; the method to be executed is determined at runtime based on the object. |
Why do we need Abstract classes ? | Abstract classes are used to define a common base with shared methods and properties that derived classes can implement. They provide a template and enforce that certain methods must be implemented by subclasses. |
Difference between Abstract Class & Interfaces? | Abstract Class: Can have both abstract and concrete methods, supports inheritance, and can have fields and constructors.
Interface: Only has abstract methods (in most cases), cannot have fields, constructors, or any implementation details, and supports multiple inheritance. |