0% found this document useful (0 votes)
12 views2 pages

Exp 2.1 Java

The document outlines an experiment for a student named Aman Kumar Bhati in a Java programming course, focusing on inheritance through the creation of an Animal class and a derived Bird class. The objective is to study different types of inheritance by implementing methods such as walk(), fly(), and sing(). The document includes the algorithm, program code, and expected learning outcomes related to class inheritance in Java.

Uploaded by

amanbhati9528
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)
12 views2 pages

Exp 2.1 Java

The document outlines an experiment for a student named Aman Kumar Bhati in a Java programming course, focusing on inheritance through the creation of an Animal class and a derived Bird class. The objective is to study different types of inheritance by implementing methods such as walk(), fly(), and sing(). The document includes the algorithm, program code, and expected learning outcomes related to class inheritance in Java.

Uploaded by

amanbhati9528
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
You are on page 1/ 2

Student Name: Aman kumar bhati UID: 21BCS2982

Branch: BE-CSE Section/Group: 609-A


Semester: 3rd Date of Performance:
16/9/22 Subject Name: OOPS using JAVA Subject Code: 21CSH-211

Experiment: 2.1
AIM: Consider the Animal class that has only one method, walk(). Next, we want to create a
derived class called Bird from Animal class that has a fly() method.Finally, we can create a
Bird object that can call both fly() and walk(). You must add a sing method to the Bird class,
then modify the main method accordingly so as to get the desired output.

S/W Requirement: NetBeans/Visual Studio Code

Objective: To study different types of inheritance in java.

Algorithm/Syntax:
class Subclass-name extends Superclass-name
{
//methods and fields
}
//Type of inheritance
class Animal{
void eat(){System.out.println("eating...");}
}
class Dog extends Animal
{
void bark(){System.out.println("barking...");}
}
class Cat extends Animal
{
void meow(){System.out.println("meowing...");}
}
class TestInheritance3
{
public static void main(String args[])
{
Cat c=new Cat();
c.meow();
c.eat();
//c.bark(); //Compile Time Error
}
}
Program Code:
class Animal{
void walk()
System.out.println("I am walking");
}
class Bird extends Animal
{
void fly()
System.out.println("I am flying");
void sing()
System.out.println("I am singing");
}
public class Solution
{
public static void main(String[] args) {
Bird bird = new Bird();
bird.walk();
bird.fly();
bird.sing();
}
}

Output:

Learning outcomes:
1. How to inherit in java
2. How to extends the class

You might also like