JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Code written to show inheritance
//Notice that inheritance works like this:
//Animal>Mammal>Dog, Cat, Human
//Animal>Reptil>Snake
//Upvote if code helps you ^^
public class Program
{
public static void main(String[] args) {
Dog dog = new Dog();
Cat cat = new Cat();
Human human = new Human();
Snake snake = new Snake();
//We instantiate each animal
dog.eat();
cat.eat();
human.eat();
snake.eat();
//Each animal do 'eat'
System.out.println("dog:" + dog.time + "sec."); //print dog lunch time
System.out.println("cat:" + cat.time + "sec.");
//print cat lunch time
System.out.println("human:" + human.time + "sec.");
//print human lunch time
System.out.println("snake:" + snake.time + "sec.");//print snake lunch time
}//end main method
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run