Encapsulation, Inheritance & Polymorphism - OOP principles
The three OOP principles
- Encapsulation
- Inheritance
- Polymorphism
1. Encapsulation
➡ Methods in java is near about same as the functions in c programming language.
A sequence of process steps can become a collection of message between these objects,
purpose of a class is to encapsulate complexity and to provide security.
There are public and private methods.
Public methods are accessible throughout the program, while private methods are accessible to that class only. they are not accessible outside the class in which they are declared.
2. Inheritance
➡ It is the process by which objects of one class acquire the properties of objects of another class.
➡ It supports the concept of Hierarchical classification.
➡ It provides the the idea of reusability. It means we can add additional features to an existing class without modifying it.
It allows programmer to reuse a class that is almost, but not exactly, what he wants, and to tailor the class in such a way that it does not introduce any undesirable side effects into the rest of the classes.
➡ The derived class is known as 'subclass'.
3. Polymorphism
➡ Polymorphism means the ability to take more than one form.
Polymorphism in Java is a concept by which we can perform a single action in different ways. Thre are two types of polymorphism in Java: Compile-time polymorphism and runtime polymorphism. We can perform polymorphism in java by method oerloading and method overriding which we will discuss later-on in our syllabus.
Keep enjoying.
Make sure you subscribe to the blog.
Comments