Oops Inheritance
Oops Inheritance
INHERITANCE
A PowerPoint Presentation
By
T. PARTHASARADHI
OOPS Concepts using JAVA
OOPs is an Object Oriented programming Paradigms.
It is the concept of Programming Language like C#,
Java using real world entity.
They are:
• Objects • Class
• Abstraction • Encapsulation
• Inheritance • Polymorphism
• Single Inheritance
• Multilevel Inheritance
• Hierarchical Inheritance
• Multiple Inheritance
• Hybrid Inheritance
Single Inheritance
When a Subclass is derived only from a single
Superclass, then it is known as single inheritance.
SuperClass(A)
SubClass(B)
OUTPUT:
I am from class A
I am from class B
Multilevel Inheritance
The process of deriving the new class from a
derived class is known as multilevel inheritance.
Base class(A)
Derived class(C)
class Animal
{
public void eat( )
{
System.out.println(“eating”);
}
}
class Dog extends Animal
{
public void bark( )
{
System.out.println(“barking”);
}
}
JAVA Program to Implement Multilevel Inheritance
Class hutch extends Dog Output:
{ Sniffing
public void sniff( ) Barking
{
System.out.println(“sniffing”); eating
}
}
Class Inherit
{
public static void main(String
args[])
{
hutch ruby = new hutch( );
ruby.sniff( );
ruby.bark( );
ruby.eat( );
}
}
Hierarchical Inheritance
The process of deriving multiple subclasses from
a single super or base class.
Class A
class hierarchical
{
public static void main(String args[ ])
{
Cat c=new Cat();
c.meow();
c.eat();
}
}
Output:-
meowing...
eating…
Multiple Inheritance
The process of deriving a subclass from more than one
superclass is known as multiple inheritance.
SuperClass (A) SuperClass (B)
SubClass (C)
Output:-
fried chicken is prepared
eating fried chicken
Advantages and Inheritance
• The main advantage of the inheritance is that it helps
in reusability of the code.