The Four Pillars Of OOP

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Inheritance:

Inheritance defines as when a class acquire all the properties of another class that means all the methods and data members are acquired by the class.And in java this can be done by using extends keyword.The class from which we acquire properties is called “parent” class and the other one is called “child” class.This established a “is-a” relationship between the class.We can relate this better with parents and their children example like a child get the genes passed on from their parents like eye color,height etc.

Example of inheritance in java

Encapsulation:

Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit or we can say that binding the data with methods.It provides more controlled access over the data.

  1. declaring the variables of the class as private
  2. use of setter and getter to access the variables
Example of encapsulation in java

Abstraction:

Abstraction is a process of hiding the implementation details and showing only the functionality to the user.

Example of Polymorphism in java

Polymorphism:

In simple words it means “many forms” , In object oriented programming language like java we can say polymorphism is a concept by which we can perform a single action in different ways.

  1. Compile-time Polymorphism(Method Overloading)
  2. Run-time Polymorphism(Method Overriding)
Example of Polymorphism in java

Conclusion:

oops concepts are really good when it comes to solve real world problems that is why it gained its popularity so fast.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store