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() {
[Link]("I am eating ..... ");
}
}
class Dog extends Animal {
void bark() {
[Link]("I am barking ..... ");
}
}
class AnimalKingdom extends Animal {
void habitat() {
[Link]("We live in various habitat. ... ");
}
}
class Lion extends AnimalKingdom {
void roar() {
[Link]("I am roaring ...... ");
University Institute of Engineering
Department of Electronics & Communication Engineering
}
}
class Bird extends Animal {
void fly() {
[Link]("I am flying ...... ");
}
}
class Parrot extends Animal {
void speak() {
[Link]("I am speaking ...... ");
}
}
public class InheritanceDemo{
public static void main(String[] args) {
[Link](" ");
[Link]("Single Inheritance .... ");
Dog d = new Dog();
[Link]();
[Link]();
[Link](" ");
[Link]("Multilevel Inheritance .... ");
Lion l = new Lion();
[Link]();
[Link]();
[Link]();
[Link](" ");
[Link]("Hierarchical Inheritance .... ");
Bird b = new Bird();
[Link]();
[Link]();
Parrot p = new Parrot();
University Institute of Engineering
Department of Electronics & Communication Engineering
[Link]();
[Link](" ");
}
}
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.