OOPS (object oriented programming )
what is object oriented programming and types of oops ?
The object-oriented programming model revolves around the concept of Objects. What is an Object? An object is an instance of a Class. It contains properties and functions. They are like real-world objects. For example, your car, house, laptop, etc. are all objects. They have some specific properties and methods to perform some action. What is a Class? The Class defines the blueprint of Objects. They define the properties and functionalities of the objects. For example, Laptop is a class and your laptop is an instance of it.
oops concepts
- Abstraction
- Encapsulation
- Polymorphism
- Inheritance
1. Abstraction
Abstraction is the concept of hiding the internal details and describing things in simple terms. For example, a method that adds two integers. The internal processing of the method is hidden from the outer world. There are many ways to achieve abstraction in object-oriented programming , such as encapsulation and inheritance. A Java program is also a great example of abstraction. Here java takes care of converting simple statements to machine language and hides the inner implementation details from the outer world.
2. Encapsulation
Encapsulation is the technique used to implement abstraction in object-oriented programming. Encapsulation is used for access restriction to class members and methods. Access modifier keywords are used for encapsulation in object oriented programming. For example, encapsulation in java is achieved using private
, protected
and public
keywords
3. Polymorphism
Polymorphism is the concept where an object behaves differently in different situations. There are two types of polymorphism - compile time polymorphism and runtime polymorphism. Compile-time polymorphism is achieved by method overloading. For example, we can have a class as below.
4. Inheritance
Inheritance is the object-oriented programming concept where an object is based on another object. Inheritance is the mechanism of code reuse. The object that is getting inherited is called the superclass and the object that inherits the superclass is called a subclass. We use extends
keyword in java to implement inheritance. Below is a simple example of inheritance in java.