OOPs concept in java

What are the OOPs concepts in JAVA?


There aren mainly 4 core concept of OOPs in JAVA,following are given below as:


1) Inheritance 

2) Polymorphism

3) Abstraction

4) Encapsulation


Let explain each concept briefly one by one-

1)Inheritance-


Acquiring the property of parent class simply called as inheritance.Means in java we can achieve reusability concept.In java if any class inherit another class  using extends keyword.Extended class knows as base class, parent class ,or super class and class which inherit superclass also know as child class.


Example :


public class A{}


class B extends class A {}


So A class behaves as super class and class B is child class of class A. 

2)Polymorphism-


Polymorphism is described as  “one interface ,many implementations” ,so polymorphism is characteristic of being assigned a different meaning or used to in different contexts ,also it allows any entity like members ,methods to appear in more than one forms.


In java it can be achieved by -

  1. Overriding

  2. Overloading

3)Abstraction-

Abstraction comes under the scene if you are dealing with only ideas not on events,it means without showing internal implementation focuses only showing essential things or functionality to the user.


In java it can be achieved by -


  1. Abstract class(0-100% abstraction)

  2. Interface(100%) interface

4) Encapsulation-


This is a concept of data hiding means combining all data like methods ,class members into a single unit. It can not appear to be accessible or modifiable from the outside world directly.  If you want any modification in their members of class you have to use the setter method ,to access the members you have to use the getter methods of the class.  



In you can achieve it by -

  1. Using getter and setter inside the class

  2. Using the access modifier private


There are some more concepts related to oops like composition,aggregation.



Comments