-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava.txt
More file actions
81 lines (63 loc) · 1.33 KB
/
Copy pathjava.txt
File metadata and controls
81 lines (63 loc) · 1.33 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
class Main {
public static void main(String[] args) {
// Cat cat_obj = new Cat();
// cat_obj.calling();
Dog dog_obj = new Dog();
dog_obj.calling();
Human human_obj = new Human();
human_obj.eat();
human_obj.walk();
}
}
class Animal
{
//which sound does animal provide
public void sound(String sound)
{
System.out.println("Animal Sound is : "+" "+sound);
}
// which food does animal eat
public void food(String animal_name, String animal_food)
{
System.out.println(animal_name+" "+"eat"+" "+animal_food);
}
}
// Cat class which represend the speacification of cat
class Cat
{
public void calling()
{
Animal animal_obj = new Animal();
animal_obj.food("Cat", "Raw meat");
}
}
// Dog class which represend the speacification of cat
class Dog
{
public void calling()
{
Animal animal_obj = new Animal();
animal_obj.food("Dog", "Bone");
}
}
// Tiger class which represend the speacification of cat
class Tiger
{
public void calling()
{
Animal animal_obj = new Animal();
animal_obj.food("Tiger", "Raw meat of animal");
}
}
//Examples of inheritance
class Walk
{
public void walk(){
System.out.println("Human can walk.");
}
}
class Human extends Walk{
public void eat(){
System.out.println("Human can eat.");
}
}