Demo Presentation
Demo Presentation
“Inheritance”
Sidra Rani
Riphah School of Computing and Innovation
What is Inheritance
Single Inheritance
Multilevel Inheritance
Multiple Inheritance
Hierarchal Inheritance
Hybrid Inheritance
Single inheritance
When a class extends another
one class only then we call it a
single inheritance. The below flow
diagram shows that class B
extends only one class which is A.
Here A is a parent class of B and
B would be a child class of A.
Multiple Inheritance
"Multiple Inheritance" refers to
the concept of one class
extending (Or inherits) more than
one base class.
The problem with "multiple
inheritance" is that the derived
class will have to manage the
dependency on two base classes.
Multilevel inheritance
Multilevel inheritance refers to a
mechanism in which one class
can inherit from a derived class,
thereby making this derived class
the base class for the new class.
As you can see in below flow
diagram C is subclass or child
class of B and B is a child class of
A.
Hierarchical
Inheritance
In such kind of inheritance one
class is inherited by many sub
classes.In below example class
B,C and D inherits the same class
A.A is parent class (or base
class) of B,C & D.
Single Inheritance
Example:
Class A
{
Public void methodA ()
{
System.out.println("Base class method”); }
}
Class B extends A
{
public void methodB()
{
System.out.println("Child class method");}