Basic Oops concept are :
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
1. Inheritance :
Inheritance is one such concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes.
In Java, there are two classes:
Inheritance is one such concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes.
In Java, there are two classes:
- Parent class ( Super or Base class)
- Child class (Subclass or Derived class )
Read more about Inheritance here.
2. Polymorphism :
Polymorphism means taking many forms, where ‘poly’ means many and ‘morph’ means forms. It is the ability of a variable, function or object to take on multiple forms. Polymorphism in Java is of two types: - Run time polymorphism
- Compile time polymorphism
Read more about Polymorphism here
3. Encapsulation :
Encapsulation is a mechanism where you bind your data and code together as a single unit. It also means to hide your data in order to make it safe from any modification. We can achieve encapsulation in Java by:
Declaring the variables of a class as private. Providing public setter and getter methods to modify and view the variables values.
Abstraction is process of hiding the implementation details and showing only the functionality.
Abstraction in java is achieved by using interface and abstract class. Interface give 100% abstraction and abstract class give 0-100% abstraction.
Read more about Abstraction here.