As we already know java is the truly object-oriented programming language.
It means we implemented real-world entities (object, classes, abstraction, inheritance, polymorphism, etc.) by using a programming language
So, let’s know about object-oriented programming in java
It is a type of programming language in which we deal with the object and classes
Or in this programming Entire program is divided into objects.
In oops we follow the bottom-up approach of programming
Concept of object-oriented:
In this article, we understand the basic concept of oops.
Following are the oops concept :
Let’s understand them one by one
The object is the real-world entity which has state and behavior
in the real world cars, table, chair, dog, phone, etc. is an object
They all have state and different behavior (their function)
Similarly in Oops
A software bundle of variable and related methods are used to model real-world entity is called an object
Or an object is an instance of the class
Object interact and communicate with each other using message
The formal definition of class is
A class is a blueprint or protocol the variable and method common to all object of a certain kind
In real-word, you see any object of the same kind. For example, a bicycle is just one of many bicycles in the word
Using object-oriented terminology we say that bicycle is an instance of the class
You could create a bicycle class that declares several instance variable to contain the current gear, the current cadence, and so on for each bicycle object. The class would also declare and provide the implementation for the instance method that allows the rider to change ear, break and change the pedaling cadence.
As you acquire the property of your parents
Similarly in java class and method also acquire the property of there parent’s class and method.
It is used to achieve run-time polymorphism.
The word polymorphism is a Greek word that means many forms.
Polymorphism is a feature that allows one interface to used for a general class of action
Polymorphism is often expressed by the phrase “one interface, multiple methods”
In Java, we use method overloading and method overriding to achieve polymorphism
In simple When you go to ATM you simply give the command to ATM and get money but you don’t know what background process is going on
This is called abstraction
Hiding the internal detail and showing the main function is known as an abstraction
In java to archive abstraction, we use the abstract class
Encapsulation is the mechanism that binds together code and the data manipulate, it and keeps both safes from the outside interface and misuse encapsulation is a protective wall that prevents the code and data from being randomly accessed by other code defined outside the wall.
For example, a capsule is wrapped with different medicines. Is an Encapsulation