0% found this document useful (0 votes)
49 views14 pages

Inheritance

The document discusses different types of inheritance in object-oriented programming including single, multiple, multilevel, hierarchical and hybrid inheritance. Single inheritance allows a class to inherit from one parent class. Multiple inheritance allows a class to inherit from multiple parent classes. Multilevel inheritance involves deriving a class from another derived class. Hierarchical inheritance involves deriving multiple classes from a single base class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views14 pages

Inheritance

The document discusses different types of inheritance in object-oriented programming including single, multiple, multilevel, hierarchical and hybrid inheritance. Single inheritance allows a class to inherit from one parent class. Multiple inheritance allows a class to inherit from multiple parent classes. Multilevel inheritance involves deriving a class from another derived class. Hierarchical inheritance involves deriving multiple classes from a single base class.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Prof. Cherry Mae J.

Galangque, MSCA

email: [email protected]
Computer Engineering Program, DEET
College of Engineering and Technology
Mindanao State University - Iligan Institute of Technology
▪ Inheritance
is one of the feature of Object Oriented Programming
System(OOPs)that allows the child class to acquire the properties (the data
members) and functionality (the member functions) of parent class.
▪ What is child class?
A class that inherits another class is known as child class, it is also known as
derived class or subclass.
▪ What is parent class?
The class that is being inherited by other class is known as parent class, super class
or base class.
▪ Syntax of Inheritance
class parent_class {
//Body of parent class
};

class child_class : access_modifier


parent_class {
//Body of child class
};
class Animal {
// eat() function
// sleep() function
};

class Dog : public Animal {


// bark() function
};
A publicly derived class inherits access to every member of a base class except:

▪ its constructors and its destructor


▪ its assignment operator members (operator=)
▪ its friends
▪ its private members

Calling a different constructor of a base class is possible, using the same syntax used to
initialize member variables in the initialization list:

derived_constructor_name (parameters) : base_constructor_name (parameters) {


...
}
1) Single inheritance
2) Multiple inheritance
3) Multilevel inheritance
4) Hierarchical inheritance
5) Hybrid inheritance
▪ In single inheritance, a class is allowed to inherit from
only one class. i.e. one sub class is inherited by one
base class only.
▪ Multiple Inheritance is a feature of C++ where a class can inherit from more than one
classes. i.e one child class is inherited from more than one base classes.
Syntax:
class childclass_name : access_mode base_class1, access_mode base_class2, ....{
//body of subclass
};
▪ In this type of inheritance, a derived class is
created from another derived class
▪ In this type of inheritance, more than one sub
class is inherited from a single base class.
i.e. more than one derived class is created
from a single base class.
▪ Hybrid Inheritance is implemented by
combining more than one type of inheritance.
▪ For example: Combining Hierarchical
inheritance and Multiple Inheritance.

You might also like