The object is Real-world entities i.e Pen, Paper, computer, watch, fan, etc.
Object-Oriented Programming is a paradigm or methodology to implement real-world entities by design a program using classes and objects.
OOPS(Object-Oriented programming System) provides a paradigm to simplifies the development and maintenance of a Software. Here are the main concepts of OOPS:
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Apart from these basic concepts, there are some other terminologies used to show association and dependency between the objects: and classes:
- Coupling
- Cohesion
- Association
- Aggregation
- Composition
- Generalization(Super Class)
- Specialization (Sub Class)
- Realization(Interface)
See Also:
- Java: Class & Instance Relationship
- Java: OOPS Design Principles
- Java: SOLID Design principles
simula and Smalltalk are considered as first truly object-oriented programming language But the main popular object-oriented languages are Java, C#, PHP, Python, C++, etc.
Object
A physical or logical entity that has state and behavior are known as an object. For Example Pen, Paper, computer, watch fan, etc.
An Object is an instance of a class. It contains an address and takes some space in heap memory. Communication between objects happens without knowing the detail of each other only condition is the type of message accepted and the type of response returned should be compatible.
For Example, A car is an object because it has states like color, make, model, engine, etc. as well as behaviors like speed, accelerator, music, etc.
Class
The collection of objects is called a class. Class is the blueprint of an object from which object created. Class doesn’t consume space.
For Example, Person is class and “Saurabh Gupta” is the object of that class.
Inheritance
Inheritance is a process where child class acquired all the properties and behaviors of the parent class. Inheritance is used when one object is based on another object. Here parent class also called a superclass and child class called as a subclass.
For Example, Person is Parent class and Employee is a subclass of Person. which acquired all the properties and behavior of Person class.
Advantage of inheritance
- Code Reusability
- Runtime Polymorphism
Points about Inheritance
- extends the keyword used to implement inheritance.
- Java doesn’t support multiple inheritances. It’s possible by implementing multiple interfaces.
- Inheritance has an “IS-A” relationship.
Polymorphism
Polymorphism (more-form) means the ability to take more than one form. It’s used when one task needs to perform in different ways.
For Example, areas of shape are having different formulae for each same like rectangle, square, circle, etc.
Polymorphism can be achieved in two ways:
Abstraction
Abstraction is a concept to show only essential detail i.e hide internal detail and show functionality in simple terms. To achieve abstraction in Java, use abstract class or interface.
Example: In ATM we don’t know how internally work. In Car don’t know about the internal mechanism.
Abstraction can be achieved by two ways:
- Abstract Class (0% to 100%)
- Interface (100%)
Encapsulation
Binding (or wrapping) of data and function in a single unit is called encapsulation. The encapsulation technique is used to achieve abstraction in oops.
In Java, A class is an example of encapsulation where abstraction level depends on access modifiers(private, protected and public) uses for fields and methods. A class is considered as fully encapsulated if all data members are private.
Nice notes for Java Oops concepts.. Very easy to understand ..