You are on page 1of 10

JAVA

Inheritance

Pothan Prasad Pabbuleti


Topics

Introduction of Inheritance.

 Example program.

Types of the Inheritance.


Introduction
• Definition

• Daily life Example

• Features of Inheritance

• Example program
Features of Inheritance
• Reusability – Inheritance allows code
reusability.

• Refinement – Adding the new


functionality to the existing component
without modifying the component
Example Program
class figure { class inheritance {
int l,b,area; Public static void main(String args[]) {
void showarea(){ rectangle rect = new recatangle(3,4);
Area = l*b; Rect.showarea();
System.out.println(“The area = “+area); square sqr = new square(4);
}} sqr.showarea();
class rectangle extends figure{ }}
rectangle(int len, int wid){
l = len; OUTPUT:
b = wid; } } The area = 12
class square extends figure { The area = 16
Square(int len)
l=len;
b=len;
Types of Inheritance
1. Single Inheritance

3. Multilevel Inheritance

5. Hierarchical Inheritance

7. Multiple Inheritance
Single Inheritance

A Super class

B Sub class
Multilevel Inheritance

C
Hierarchical Inheritance

B C C
Multiple Inheritance

B A

Click here for another example program.