Abhinav Computer 12
Abhinav Computer 12
Abhinav Computer 12
Object-oriented programming
2. Encapsulation:
• Encapsulation is the bundling of data (attributes)
and methods that operate on the data into a single unit
(class).
• Access to the data is controlled through methods
(getters and setters), allowing for better data security
and code maintainability.
3. Inheritance:
• Inheritance is a mechanism that allows a class
(subclass/derived class) to inherit properties and
behaviors from another class (superclass/base class).
• Subclasses can extend the functionality of the
superclass by adding new methods or overriding
existing ones.
4. Polymorphism:
• Polymorphism allows objects of different
classes to be treated as objects of a common
superclass through inheritance.
• It enables methods to be invoked on objects
of different classes in a unified manner, based on
the actual type of the object at runtime.
• Polymorphism is achieved through method
overriding (runtime polymorphism) and method
overloading (compile-time polymorphism).
5. Abstraction:
• Abstraction is the process of hiding the
implementation details of a class and exposing only the
essential features (interface) to the outside world.
• Abstract classes and interfaces are used to define
abstractions in Java.
• Abstract classes cannot be instantiated and may
contain abstract methods (methods without a body),
while interfaces define a contract that implementing
classes must adhere to.