What is OOPS ? | Concept of OOPS | JAVA programming
What is OOPS?
Object-oriented programming is a programming concept based on the principle that objects are the most important part of your program.
Lets users create the desired objects and then create methods to manage those objects. Handling these objects for results is the goal of object-oriented programming.
Object-oriented programming, better known as OOP, is used in a modern programming language such as Java.
The basic concepts of OOPS are
(1) Class
The class is a group of similar entities. It's just a logical component and not the physical entity.
For example,
if you have a class called Costly Cars, it may include items such as Mercedes, BMW, Toyota, etc. Their characteristics (data) can be the price or the speed of these cars. While methods can be done with these cars, drive, reverse, brake, etc.
(2) Object
An object can be defined as an instance of a class and a program can contain multiple instances of a class.
An object contains both the data and the function that works with the data.
For example
chair, bike, marker, pen, table, car, etc.
(3) The Inheritance
Inheritance is an OOPS concept in which an object captures the properties and behavior of the parent object.
A parent-child relationship is established between two classes. It provides a robust and natural mechanism for organizing and structuring any software.
(4) Polymorphism
Polymorphism refers to the ability of a variable, object, or function to take many forms.
For example,
In English, the verb has a different meaning when you use it with a laptop, a race and a company.
Here we understand the term meaning based on the other words used together with term. The same is true for polymorphism.
(5) Abstraction
An abstraction consists in presenting the essential characteristics without taking into account the details of the background. This is a technique for creating a new data type that is suitable for a particular application.
For example,
If you drive a car, you do not have to worry about internal work. Here, you only need to worry about parts such as the steering wheel, the transmission, the accelerator pedal, and so on.
(6) Encapsulation
Encapsulation is a OOP technique for encapsulating data and code. In this OOPS concept, variables in one class are always hidden from other classes.
It could only be accessed using the methods of their current class.
For example,
At school, a classless student can not exist.
(7) Association
Association is a relationship between two objects. It defines the diversity between objects.
In this OOP concept, all objects have a distinct life cycle and there is no owner.
For example, many students may be assigned to one teacher, while one student may be assigned to more than one teacher.
(8) Aggregation
In this technique, all objects have their own life cycle. However, there are property rights so that children can not belong to any other parent.
For example, consider the class / object department and the teacher. Here, only one teacher can not belong to more than one department, but even if we delete the department, the teaching object is never destroyed.
(9) composition
A composition is a particular form of aggregation. It is also called "relationship of death". Child objects do not have a life cycle.
If the parent object deletes all child objects, they will also be deleted automatically. Take an example of the house and the room. Each house can have several rooms.
A room can not be part of two different houses. So if you delete the house, the room will also be deleted.
Benefits of OOPS:
✓ OOP provides a clear and easy-to-understand modular structure for programs.
✓ Objects created for object-oriented programs can be reused in other programs. This saves considerable development costs.
✓ Large programs are hard to write, but if the development and design team follows the OOPS concept, they can design better with minimal errors.
✓ This also improves the modularity of the program because each object exists independently.
0 comments: