Object-Oriented Programming is a programming paradigm which is based on the concept of objects. Here objects contains 2 things data and code. Data can be in the form of fields. In other words fields can be called attributes or properties.
Concepts in Object-Oriented Programming
Objects are conceptually similar to real-world objects. They too consist of state and related behavior. An object stores it’s state in fields and exposes it’s behavior through methods. In Java we can create object using ‘new’ keyword.
Your room is Living Room
A class is the blueprint from which individual objects are created.
In real world too you can find many individual objects all of the same kind.
Your NewsPaper has 16 pages.
Different kinds of objects often have a certain amount in common with each other. Mountain bikes, road bikes and tandem bikes all share the characteristics of bicycles( current speed, current gear).
Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.In Java programming language, each class is allowed to have one direct super-class, and each super-class can have any number of sub-classes.
Number of gear=4
There are 3 types of inheritance in java. These are
a). Single Inheritance:
In this type of inheritance one class inherit properties of it’s parent class. For Example Car class can inherit properties of vehicle class.
Number of wheels=4
Vehicle run on petrol
b). Multi-level Inheritance:
In this type of inheritance parent class is having their own parent class like grand parents in real life.
c). Hierarchy Inheritance:
In this type of inheritance one parent can have more than one child like we have siblings in our real life.
Car capacity is to carry 4 people.
It run on petrol
Tractor can lift 100 kg of sand.
It run on petrol
The process of combining data and code together is called encapsulation.
We can use private keyword and use setter and getter to implement encapsulation in java.
Abstraction is the process to show only necessary things to user and hide implementation. Like in real life we apply brake in bike and it stop but we don’t know how internally it works.
We can implement abstraction using abstract class or interfaces in java.
Number of wheels in Car 4
Polymorphism in java is a concept by which we can perform single action in different ways. Using this objects can take many forms.
In java polymorphism is of 2 types.
- Compile time polymorphism: is implemented using method overloading.
- Run time polymorphism : is implemented using method overriding.
Object oriented programming helps in solving real world problems. For more detail study you can refer to Object-Oriented Programming Concepts.