CMSC 203 Module 4
CMSC 203 Module 4
Single Inheritance
• A derived class inherits from only one base class.
Multiple Inheritance
• A derived class inherits from more than one base class.
• This can introduce complexity and is handled
differently in various programming languages
Single vs Multiple Inheritance
Code Reusability
• Common functionality can be written once in the base
class and reused by derived classes, reducing
redundancy.
Code Organization
• Inheritance promotes a hierarchical class structure that
logically organizes code and simplifies maintenance.
Extensibility
• New classes can be created by extending existing ones,
making it easier to introduce new functionality without
altering existing code.
Method Overriding
• Occurs when a subclass (child class) provides a
specific implementation for a method that is already
defined in its superclass (parent class).
• The overridden method in the subclass should have the
same name, return type, and parameters as the method
in the superclass.
Purpose of Method Overriding
• To allow a subclass to provide a specific
implementation of a method that is already defined in
its superclass.
• Enables polymorphism, where a subclass can be treated
as an instance of its superclass, but it can behave
differently depending on the method implementation in
the subclass.
Method Overloading
• Occurs when multiple methods with the same name are
defined in the same class, but with different parameter
lists (different types, numbers, or both).
• The return type of the methods can be the same or
different.
Simulating Method Overloading