Object-oriented programming System(OOPs)
is a programming paradigm based on the concept of “objects” that contain data and method's. The basic goal of object-oriented programming is to make code more flexible and maintainable.
oop in java |
It makes software development and maintenance easier by introducing the following concepts:
Let us know briefly about each concept :
1.Object :
An object is any entity that has state and behavior. For example, a chair, pen, table, keyboard, bicycle, and so on. It might be physical or logical in nature. An Object can be defined as an instance of a class.
Example: A car is an object because it has states like color, name, company, etc. as well as behaviors like start, stop, move etc.
2.Class :
Collection of objects is called class. class can be considered as a blueprint using which you can create as many objects as you like.
3.Inheritance :
The process by which one class acquires the properties and functionalities of another class is called inheritance. It provides code reusability.
Inheritance is a process of defining a new class based on an existing class by extending its common data members and methods.
The parent class is called the base class or super class. The child class that extends the base class is called the derived class or sub class or child class.
there are four type of inheritance in java;
1.Single Inheritance:
refers to a child-parent class relationship in which one class extends the another class.
2. Multilevel Inheritance :
refers to a child and parent class relationship where a class extends the child class.
3. Hierarchical Inheritance :
refers to a child and parent class relationship where more than one classes extends the same class.
4. Multiple Inheritance :
refers to the concept of one class extending more than one classes, which means a child class has two parent classes. Java doesn’t support multiple inheritance.
4. Hybrid Inheritance :
like multiple inheritance java does not support Hybrid inheritance. To reduce the complexity and simplify the language, multiple/Hybrid inheritance is not supported in java
Polymorphism occurs when a single task is performed in multiple ways.
In Java, we use method overloading and method overriding to achieve polymorphism.
Types of Polymorphism:
- Static polymorphism
- Dynamic Polymorphism
5. Abstraction :
Hiding internal details and showing functionality is known as abstraction. For example phone call, we don't know the internal processing. In Java, we use abstract class and interface to achieve abstraction.
6. Encapsulation :
Encapsulation simply means binding object state(fields) and behavior(methods) together. If you are creating class, you are doing encapsulation.
Tags:
Java