0% found this document useful (0 votes)
2 views

ankit java exp3

Uploaded by

vidhanshu9086
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ankit java exp3

Uploaded by

vidhanshu9086
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

University Institute of Engineering

Department of Electronics & Communication Engineering

EXPERIMENT - 3
Student Name: Ankit Kumar UID:23BEC10026
Branch: Electronics and Communications Section/Group:23BEC-1(A)
Semester: 3th Date of Performance:07-08-2024
Subject Name: JAVA PROGRAMMING

1. Aim of the practical: Write a program to learn different types of inheritance in java.

2. Tool Used: Online java compiler


3. Theory: To study the execution of inheritance and its different types.

Code:
class Animal {
void eat() {
System.out.println("I am eating ..... ");
}
}

class Dog extends Animal {


void bark() {
System.out.println("I am barking ..... ");
}
}

class AnimalKingdom extends Animal {


void habitat() {
System.out.println("We live in various habitat. ... ");
}
}

class Lion extends AnimalKingdom {


void roar() {
System.out.println("I am roaring ...... ");
University Institute of Engineering
Department of Electronics & Communication Engineering
}
}

class Bird extends Animal {


void fly() {
System.out.println("I am flying ...... ");
}
}

class Parrot extends Animal {


void speak() {
System.out.println("I am speaking ...... ");
}
}

public class InheritanceDemo{


public static void main(String[] args) {
System.out.println(" ");
System.out.println("Single Inheritance .... ");
Dog d = new Dog();
d.eat();
d.bark();
System.out.println(" ");
System.out.println("Multilevel Inheritance .... ");
Lion l = new Lion();
l.eat();
l.habitat();
l.roar();
System.out.println(" ");
System.out.println("Hierarchical Inheritance .... ");
Bird b = new Bird();
b.eat();
b.fly();
Parrot p = new Parrot();
University Institute of Engineering
Department of Electronics & Communication Engineering
p.speak();
System.out.println(" ");
}
}

Output -
Single Inheritance.....
I am eating......
I am barking......

Multilevel Inheritance.....
I am eating......
We live in various habitat.....
I am roaring.......
University Institute of Engineering
Department of Electronics & Communication Engineering

Hierarchical Inheritance.....
I am eating......
I am flying.......
I am speaking.......

=== Code Execution Successful ===

Learning outcomes (What I have learnt):


1. Learn about java compiler.
2. Learn about the execution of inheritance and its different
types.

You might also like