-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram#F.java
More file actions
39 lines (37 loc) · 822 Bytes
/
Program#F.java
File metadata and controls
39 lines (37 loc) · 822 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
/* Create an interface Animal with methods eat() and sleep(). Implement this interface in classes Dog and Cat.
Dog eat bones
Dog sleeps in kennel
Cat eat fish
Cat sleeps in couch
*/
class Main {
public static void main(String [] args)
{
Dog s1 = new Dog();
Cat s2 = new Cat();
s1.eat();
s1.sleep();
s2.eat();
s2.sleep();
}
}
interface Animal {
void eat();
void sleep();
}
class Dog implements Animal {
public void eat(){
System.out.println("Dog eat bones");
}
public void sleep(){
System.out.println("Dog sleeps in kennel");
}
}
class Cat implements Animal {
public void eat(){
System.out.println("Cat eat fish");
}
public void sleep(){
System.out.println("Cat sleeps in couch");
}
}