-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch_60_exercise.java
More file actions
41 lines (34 loc) · 828 Bytes
/
Copy pathch_60_exercise.java
File metadata and controls
41 lines (34 loc) · 828 Bytes
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
interface monkey {
void eat();
void sleep();
}
class halfHuman {
public void fire() {
System.out.println("Invents Fire...");
}
}
class human extends halfHuman implements monkey {
public void eat() {
System.out.println("Eating...");
}
public void sleep() {
System.out.println("Sleeping...");
}
public void speak() {
System.out.println("Speaking...");
}
}
public class ch_60_exercise {
public static void main(String[] args) {
monkey m = new human();
// using human as monkey
m.eat();
m.sleep();
// m.speak(); // gives error as the reference is of monkey
}
}
/*
* here we use polymorphism by making the reference of monkey so that we can use
* only the methods of monkey by the object of human
*
*/