11. The pillar of OOP.

1. The first and I think the most important of OOP is abstraction.



Abstraction is used to model the relevant attributes and interactions between entites as classes and define an abstract representation of a system. We can achive abstract pillar in OOP through abstract class or interface.

2. Encapsulation is when you wrap up your data under single unit.

To achive encapsulation, you have to:

  • Declare class field with private access modifier
  • Provide public getter and setter method to access and update the value of private variable

3. Inheritant: it allows subclass can reuse all the attributes and method from parent class except private members.


There are three kinds of inheritance in OOP. There are single inheritance, multi level inheritance and hierarchical inheritance

4.Polymorphism : It’s expressed by you can execute an action in various way.

  • There are two types of polymorphsim : compile-time polymorphism achive by overloading method and runtime polymorphism achive by overloading method.
  • For example about runtime polymorphism : we start with three class animal class, dog class and cat class. Animal class has abstract method is speak() and dog class and cat class extends from animal class and it has its own speak() method. We create  a reference variable of animal class. And we can create an instance of Cat class or Dog class. The speak() method is call will be belong to this instance. Or in other way, the calling method is decided by JVM, not compiler, so it’s polymorphism at runtime

Leave a Reply

Your email address will not be published. Required fields are marked *