Single inheritance
Here we have an example of Single inheritance from an animal class which is the parent class (base) to the Dog class which is the Child class. This is signified by the syntax : that connects the child class to the base class. Click through the options below.
main program
Resulting output
derived class
Base class
The main program starts by creating an instance of the Dog class called myDog. It can then call the method Eat() (derived from the animal class) and Bark() (defined from Dog class).
The Base class contains contains a method within it called Eat() which prints to console "This animal is eating." This would always happen, no matter the amount of child classes that derive from it.
The resulting output would be as follows: The animal is eating. The dog is barking.
This class derives from the base class and has automatic access to the Eat() method. It then defines its own method Bark() which prints to console "The dog is barking."
Single inheritance
Adam Wingell
Created on March 10, 2025
Start designing with a free template
Discover more than 1500 professional designs like these:
View
Geniaflix Presentation
View
Vintage Mosaic Presentation
View
Shadow Presentation
View
Newspaper Presentation
View
Zen Presentation
View
Audio tutorial
View
Pechakucha Presentation
Explore all templates
Transcript
Single inheritance
Here we have an example of Single inheritance from an animal class which is the parent class (base) to the Dog class which is the Child class. This is signified by the syntax : that connects the child class to the base class. Click through the options below.
main program
Resulting output
derived class
Base class
The main program starts by creating an instance of the Dog class called myDog. It can then call the method Eat() (derived from the animal class) and Bark() (defined from Dog class).
The Base class contains contains a method within it called Eat() which prints to console "This animal is eating." This would always happen, no matter the amount of child classes that derive from it.
The resulting output would be as follows: The animal is eating. The dog is barking.
This class derives from the base class and has automatic access to the Eat() method. It then defines its own method Bark() which prints to console "The dog is barking."