Complete-Preparation

🎉 One-stop destination for all your technical interview Preparation 🎉

View the Project on GitHub

Pillars of OOPs

Encapsulation

Abstraction

Advantages Of Abstraction

Encapsulation and Abstraction are two different concepts. Encapsulation is about binding the data and methods together into a single unit. Abstraction is about hiding the implementation details from the user.

Inheritance

Syntax

class parent_class {
    // Body of parent class
};
class child_class : access_modifier_parent_class {
    // Body of child class
};

Modes of inheritance

  1. Public Inheritance: If we derive a subclass from a public base class. Then, the base class’s public members will become public in the derived class, and protected class members will become protected in the derived class.
  2. Protected Inheritance: If we derive a subclass from a protected base class. Then, the base class’s both public and protected members will become protected in the derived class.
  3. Private Inheritance: If we derive a subclass from a private base class. Then, the base class’s both public and protected members will become private in the derived class.
Base Class Member Access Specifier Public Protected Private
Public Public Protected Private
Protected Protected Protected Private
Private Not Accessible Not Accessible Not Accessible

Types of Inheritance

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hierarchical Inheritance
  5. Hybrid Inheritance
1. Single Inheritance

In single inheritance, one class can extend the functionality of another class. There is only one parent class and one child class in single inheritances.

2. Multilevel Inheritance

When a class inherits from a derived class, and the derived class becomes the base class of the new class, it is called multilevel inheritance. In multilevel inheritance, there is more than one level

3. Multiple Inheritance

In multiple inheritance, one class can inherit the properties of more than one class. There is only one child class and more than one parent class in multiple inheritances.

4. Hierarchical Inheritance

In hierarchical inheritance, more than one derived class is created from a single base class. There is only one parent class and more than one child class in hierarchical inheritances.

5. Hybrid Inheritance

Hybrid inheritance is a combination of more than one type of inheritance.

Polymorphism

Types of Polymorphism

  1. Compile Time Polymorphism
  2. Run Time Polymorphism
1. Compile Time Polymorphism
2. Run Time Polymorphism

Interview Questions

References