OOP Week 4 Lecture 2
OOP Week 4 Lecture 2
Week 4 lecture 2
Inheritance & Types
Inheritance
A programming technique that is used to reuse
an existing class to build new class is known as
inheritance. The new class inherits all the
behavior of the original class. The existing
class that is reused to create a new class is
known as super class, base class or parent
class. The new class inherits the properties
and functions of an existing class is known as
sub class, derived class or child class.
The inheritance relationship between the classes
of a program is called a class hierarchy.
Inheritance is the most power feature of
object oriented programming. The basic
principles of inheritance is that each sub class
shares common properties with the class from
with it is derived. The child class inherits all
capabilities of the parent class and can add its
own capabilities.
Features of inheritance
1. Reusability
Inheritance allows the developer to reuse existing
code in many situation.
2. Saves time and effort
inheritance saves a lot of time and effort to
write the same classes again.
3. Increase program structure and reliabilities
Super class is already complied and tested properly.
Categories of inheritance
1. Single inheritance:
A type of inheritance in which a child class is derived
from single parent class known as single
inheritance.
Parent
Child
2. Multiple inheritance:
A type of inheritance in which a child class is derived
from multiple parent classes is known as multiple
inheritance.
Parent 1 Parent 2
Child
Specifying a derived class
The process of specifying derived class is same
as specifying simple class. Additionally the
reference of parent is specified along with
derived class name to inherit the capabilities
of parent class.
Syntax