What is OOP??? 👇
OOP stands for Object-Oriented Programming and that concept is a programming paradigm based on the concept of "Objects" that contain data and methods. The main purpose of object-oriented programming is to increase the flexibility and maintainability of programs. Modularity for easier troubleshooting, reuse of code, flexibility, and effective problem solving are advantages of the OOP concept.
Now, let us consider what an object is...
An object is anything that has state and behavior. For example, a car, a dog, a person, etc. At runtime, when the Java Virtual Machine (JVM) encounters the new keyword, it will use the appropriate class to make an object that is an instance of that class.
Consider the car object it has state color, model, brand, weight, and as behaviors we can consider a break, accelerate, gear change.
Classes
A class can be defined as a template/ blueprint describes the behavior/state that the object of its type support. On the other hand, the class is the collection of objects.
Constructor

An object is created using the new keyword and the default constructor of the class is executed automatically. And also, there are two types of constructors.
MyClass(){
//body of constructor
}
MyClass(parametares){
//body of constructor
}
}
- No-argument constructor
- Parameterized constructor
MyClass(){
//body of constructor
}
MyClass(parametares){
//body of constructor
}
}
Object-Oriented Programming Features
- Inheritance
- Polymorphism
- Encapsulation
- Abstraction
Inheritance
The inheritance can be defined as the process where one class acquires the properties of another. The class which inherits the properties of others is known as subclass(derived class, child class) and the class whose properties are inherited is known as superclass(base class, parent class). The "extends" keyword is used to inherit the properties of a class.

Type of Inheritance
- single inheritance
- Multilevel inheritance
- Hierarchical inheritance
- Multiple inheritance
- Hybrid inheritance

Polymorphism
Polymorphism means, the same thing in different forms. In here, use Inheritance, overriding and upcasting and call the subclass method through a superclass reference.
Consider the real-world example, A person at the same time can have different characteristics. Like a person at the same time is a father or husband or son or an employee. so, the same person posses different behavior in different situations.
There are two types of polymorphism in java.
- Compile-time polymorphism - achieve through the method overloading
- Runtime polymorphism - achieve through the method overriding
Encapsulation
The encapsulation means the variable of a class will be hidden from other classes. There, Use the "Private" access modifier for hiding variables and Provide public setter and getter methods to modify and view the variable values.
Consider the real-world example, Encapsulation like a capsule. Basically, capsule encapsulate several combinations of medicine. If a Combination of medicine is variable and method, the capsule acts like a class, and the whole process is called encapsulation.
Why use encapsulation
- Better control of class attributes and methods
- Increased security of data
- Flexible -: The programmer can change one part of the code without affecting other parts.
Abstraction

Abstraction is the process of hiding certain details and showing only essential information to the user. In the abstraction, must be used abstract keyword and the abstract keyword is a non-access modifier.
Consider the real-world example, Diving a car. The man only knows that pressing the accelerator will increase the speed of the car or applying brakes will stop the car. but he does not know about how on pressing accelerator the speed is actually increasing. In other words, he does not know about the inner mechanism of the car.
Abstract class -: Abstract class is a restricted class that cannot be used to create objects.
Abstract method -: Abstract method can only be used in an abstract class ad it does not have a body.
Abstract method -: Abstract method can only be used in an abstract class ad it does not have a body.
Comments
Post a Comment