0% found this document useful (0 votes)
82 views13 pages

Object-Oriented Programming (CS F213) : BITS Pilani

This document discusses inheritance in object-oriented programming and Java. It defines inheritance as a process where a subclass acquires properties of a superclass. Examples of inheritance include animal-man and account-checking. The document also describes different types of inheritance like single, hierarchical, and multi-level inheritance. It provides examples of each type and notes that multiple inheritance is not directly supported in Java.

Uploaded by

SAURABH MITTAL
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)
82 views13 pages

Object-Oriented Programming (CS F213) : BITS Pilani

This document discusses inheritance in object-oriented programming and Java. It defines inheritance as a process where a subclass acquires properties of a superclass. Examples of inheritance include animal-man and account-checking. The document also describes different types of inheritance like single, hierarchical, and multi-level inheritance. It provides examples of each type and notes that multiple inheritance is not directly supported in Java.

Uploaded by

SAURABH MITTAL
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/ 13

Object-Oriented Programming (CS F213)

Module I: Object-Oriented and Java Basics


CS F213 RL1.3: Inheritance Basics

BITS Pilani Dr. Pankaj Vyas


Department of Computer Science, BITS-Pilani, Pilani Campus
CS F213 RL 1.3 : Topics

Inheritance
Inheritance Examples
Java Support for Inheritance [Just
Introduction]
Types of Inheritance

2 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Inheritance : Reusability
https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)

Process by which an object of one class


acquires properties of an object of other class
Supports Reusability of code and data
Inheritance Supports isA relationship
The class whose properties are extended is
known as super class (in Java) or base class (in
C++) or parent class.
The class which extends the properties of
super class is known as sub class (in Java) or
derived class (in C++) or child class

3 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Inheritance : Some Simple
Examples

Animal Super class

Man isA Animal


Man Sub class

Account Super class


Checking isA kind of
Account
Checking Sub class

Shape Super class


Circle isA Type of
Shape Sub class
Circle
4 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Inheritance in Java
class Animal
{ <<Super Class>>

// Define the Baisc Properties of Every Animal Animal

} // End of class Animal


Man
class Man extends Animal
{ <<Sub Class>>
// Define the properties that are specifically for man

}// End of class Man

5 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Types of Inheritance

Single Level Inheritance


Hierarchical Inheritance
Multi-Level Inheritance
Multiple Inheritance

6 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Types of Inheritance : Single Level

Single Level Inheritance

class A
{
A .
}// End of class A

class B extends A
B
{
..
}// End of class B

7 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Types of Inheritance : Hierarchical

Hierarchical Level Inheritance


class X
{
.
}// End of class X

X class A extends X
{
..
}// End of class A

A B C class B extends X
{
..
}// End of class B

class C extends X
{
..
}// End of class C
8 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Types of Inheritance : Hierarchical

Hierarchical Level Inheritance


class Animal
{
.
}// End of class Animal

Animal class Man extends Animal


{
..
}// End of class Man

Man Dog Frog class Dog extends Animal


{
..
}// End of class Dog

class Frog extends Animal


{
..
}// End of class Frog
9 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Types of Inheritance : Multi-Level

Multi Level (Tree) Inheritance


class A
{
..
A }// End of class A

class B extends A
{
..
B }// End of class B

class C extends B
{
C ..
}// End of class C

10 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Types of Inheritance : Multi-Level

Multi Level (Tree) Inheritance


class Vehicle
{
Vehicle ..
}// End of class Vehicle
class Two-Wheeler extends Vehicle
{
..
Two-Wheelers Four-Wheelers }// End of class Two-Wheeler
class Four-Wheeler extends Vehicle
{
..
Scooter Bike Car Jeep }// End of class Four-Wheeler
class Scooter extends Two-Wheeler
{

}// End of class Scooter

11 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Types of Inheritance : Multiple

Multiple Inheritance

A B Not Supported in
Java Directly
class A
{
.
} // End of class A
class B
{
.
C }// End of class B
class C extends A, B Wrong
{
. Not Allowed in
} // End of class C
Java
12 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas
Thank You

13 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas

You might also like