OOP principles in JAVA
Java is an object-oriented programming language, which means it is based on the principles of Object-Oriented Programming (OOP). Here are the main OOP principles in Java:
All object-oriented programming (OOP) languages introduced mechanisms that help you implement the object-oriented techniques. OOP principles in JAVA are inheritance, encapsulation, and polymorphism. Now we’ll discuss in detail one by one.
Inheritance is a technique where one object of the class acquires the properties or state of another object called Inheritance. This is most important in concepts of OOP programming. In the inheritance technique, there are the most important rules of parent class and child class or subclass. Information is made manageable in a hierarchical sequence using inheritance techniques. All subclasses or child classes can inherit the properties or state of an object from its parent classes. In inheritance, an object needs only define those attributes that make it unique within its class. It can inherit its general attributes from its parent class.
Parent Class: a class whose properties used in another class called parent class, base class, or superclass.
Child Class: a class which inherits the properties or contents of another class called child class, subclass or derived class.
Encapsulation is a technique in OOP programming where the one class data or information hide from another class called encapsulation. In simple words, encapsulation is the data hiding technique. In the capsulation technique, there are some mechanisms for hiding the complexity of the implementation codes inside the class. In a class, every variable or method may be marked as public or private. The public interface of a class represents that everything is public for external users. The private methods are accessed only by a member of the class. Therefore, any other portion of the code that is not a member of the class, can’t access a private variable or method. Since the private members or methods of a class may only be accessed by other parts of your code through the class public methods.
The word polymorphism is a combination of two poly and morphism. Poly meaning many and morphism mean form. In object-oriented programming, polymorphism is the ability of objects of different types to respond to function of the same name. The user does not have to know the exact type of the object in advance. The behavior of the object can be implemented at the run time. It is called dynamic binding or late binding. Function overloading and function overriding are the two main things for the implementation of polymorphism techniques.