Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance by providing below concepts:
- Object
- Class
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
- Any entity that has state and behavior
- instance of a class
- object contains an address & takes up some space in memory.
Class :
- Collection of objects
- logical entity
- blueprint from which you can create an individual object
- doesn't consume any space.
Inheritance :
- One object acquires all the properties and behaviors of a parent object
- provides code reusability
- used to achieve runtime polymorphism.
- Multiple inheritance is not supported in Java through class
- ambiguity
- diamond problem/deadly diamond problem/deadly diamond of death
- Java renders compile-time error.
Polymorphism:
- one task is performed in different ways
- method overloading and method overriding to achieve polymorphism.
- compile-time polymorphism : method overloading - overload a static method in Java
- runtime polymorphism/Dynamic Method Dispatch : method overriding
Abstraction:
- Hiding internal details and showing functionality
- abstract class and interface.
Abstract class (0 to 100%)
Interface (100%)
Java compiler adds public static final for elements & public abstract for methods
Multiple inheritance through interface
Encapsulation:
- Binding (or wrapping) code and data together into a single unit
- java class, Java bean is the fully encapsulated class because all the data members are private here.
Apart from these concepts, there are some other terms which are used in Object-Oriented design:
- Coupling
- Cohesion
- Association
- Aggregation
- Composition