0% found this document useful (0 votes)
5 views3 pages

Java Inheritance Examples: Single & Multilevel

The document presents a Java programming practical assignment by Vijay Pawar, a SYCO student, focusing on single and multilevel inheritance. It includes source code examples demonstrating single inheritance with a Dog class extending an Animal class, and multilevel inheritance with a BabyDog class extending Dog. The outputs for both inheritance types are also provided, showing the respective behaviors of the classes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Java Inheritance Examples: Single & Multilevel

The document presents a Java programming practical assignment by Vijay Pawar, a SYCO student, focusing on single and multilevel inheritance. It includes source code examples demonstrating single inheritance with a Dog class extending an Animal class, and multilevel inheritance with a BabyDog class extending Dog. The outputs for both inheritance types are also provided, showing the respective behaviors of the classes.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Vijay pawar

Class: SYCO
Roll No: 7
Subject: Java programming
Subject Code: 314317
Pratical Name: [Link] program to implement:
o Single inheritance
o Multilevel inheritance
---------------------------------------------------------------------------------------------------------------------------------------
Source code:
o Single inheritance
class Animal
{
void eat()
{
[Link]("This animal eats food.");
}
}
class Dog extends Animal
{
void bark()
{
[Link]("The dog barks.");
}
}
public class SingleInheritance
{
public static void main(String[] args)
{
Dog dog = new Dog();
[Link]();
[Link]();
}
}

Output:-

This animal eats food.

The dog barks.

o Multilevel inheritance

class Animal
{
void eat()
{
[Link]("Eating...");
}
}
class Dog extends Animal
{
void bark()
{
[Link]("Barking...");
}
}
class BabyDog extends Dog
{
void weep()
{
[Link]("Weeping...");
}
}
public class MultilevelInheritance
{
public static void main(String[] args)
{
BabyDog babyDog = new BabyDog();
[Link]();
[Link]();
[Link]();
}
}
Output:-
Weeping...
Barking...
Eating...

You might also like