Write a java program using Inheritance where one class acquires the properties of the other class.
- Create a java class "Animal" with a function called walk.
- Create a java class "Bird" that extends the Animal class and with two functions named fly and sing.
- Since the Bird class is extends the animal class we can access the Animal class by creating an object for the Bird class.
- In the Main.java create a object for the Bird class and access all the methods (walk,fly and sing).
- Print the output and end the program.
public class Main {
public static void main(String[] args) {
Bird bird=new Bird();
bird.walk();
bird.fly();
bird.sing();
}
}
public class Animal {
void walk(){
System.out.println("I am walking");
}
}
public class Bird extends Animal {
void fly(){
System.out.print("I am flying ");
}
void sing(){
System.out.print("I am singing");
}
}
![image](https://private-user-images.githubusercontent.com/93427376/241622013-b6500c30-17a8-403b-bda0-99a653283236.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxNjIwNTIsIm5iZiI6MTcyMjE2MTc1MiwicGF0aCI6Ii85MzQyNzM3Ni8yNDE2MjIwMTMtYjY1MDBjMzAtMTdhOC00MDNiLWJkYTAtOTlhNjUzMjgzMjM2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI4VDEwMTU1MlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM4Nzc5MmE5YjYyNzBkNDJjOTRmOWY0NzZlOTcwZTYwMjI5ODIzYjQyZGQxZGM4MDRmMmQ1N2I0MzZjZjZmN2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.kvkkj3o172O18Z_t9EZkj00kATI-yhDVqQxSGoW7I1o)
Thus a program is implemented where one class acquires the properties of the other class.