OOPS
OOPS
3 Specialized Functionality
Subclasses can add or override inherited functionality to
specialize the class for specific use cases.
Types of Inheritance
Single Inheritance Multilevel Inheritance Hierarchical Inheritance
A subclass inherits from a single A subclass inherits from a superclass, Multiple subclasses inherit from a
superclass. which itself inherits from another single superclass.
superclass.
Inheritance Syntax in Programming Languages
Java C++
class Subclass extends Superclass { ... } class Subclass : public Superclass { ... }
1 2 3
Python
class Subclass(Superclass): ...
Advantages of Inheritance
Code Reuse Polymorphism
Inheritance allows you to Subclasses can override or
reuse code from parent extend inherited methods,
classes, reducing development enabling polymorphic
time and effort. behavior.
Modularity Extensibility
Inheritance promotes a New functionality can be
modular design, making the added by creating subclasses,
codebase more organized and without modifying existing
maintainable. code.
Disadvantage of Inheritance
1 Tight Coupling 2 Complexity
Inheritance can lead to Deep inheritance
tight coupling between hierarchies can increase the
classes, making the complexity of the codebase,
codebase less flexible. making it harder to
understand and maintain.
3 Fragility
Changes in a parent class can unintentionally break functionality
in its subclasses.
Overriding and Method
Overriding
Overriding
Subclasses can override inherited methods to provide their
own implementation.
Dynamic Dispatch
The appropriate method implementation is determined at
runtime based on the object's type.
Polymorphism
Method overriding enables polymorphic behavior, where
objects of different classes can be treated as the same type.
Inheritance and Code Reusability
Code Reuse
Inheritance promotes code reuse by allowing subclasses to inherit and extend
functionality from parent classes.
Maintainability
Inheritance helps keep the codebase organized and maintainable by establishing a clear
hierarchy of related classes.
Collaboration
Inheritance enables developers to build upon each other's work, fostering collaboration
and productivity.
THANK YOU!