-
Notifications
You must be signed in to change notification settings - Fork 1
/
Interface_Inheritance.java
69 lines (69 loc) · 1.15 KB
/
Interface_Inheritance.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
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
abstract class Animals
{
abstract void eat();
}
class Spider extends Animals
{
void eat()
{
System.out.println("Spider eats insects");
}
void walk()
{
System.out.println("The animal walks by 8 legs");
}
}
interface Pet
{
void name();
}
class Fish extends Animals implements Pet
{
public void name()
{
System.out.println("This cat's name is MIMI");
}
void eat()
{
System.out.println("Cat eats fish");
}
void walk()
{
System.out.println("The animal walks by 4 legs");
}
}
class Cat extends Animals implements Pet
{
public void name()
{
System.out.println("This fish's name is MIMI");
}
void eat()
{
System.out.println("Fish eats plants");
}
void walk()
{
System.out.println("Fish has no legs");
}
}
public class Interface_Inheritance
{
public static void main(String[] args)
{
System.out.println("FISH");
Fish ob1 = new Fish();
ob1.name();
ob1.eat();
ob1.walk();
System.out.println("\nCAT");
Cat ob2 = new Cat();
ob2.name();
ob2.eat();
ob2.walk();
System.out.println("\nSPIDER");
Spider ob3 = new Spider();
ob3.eat();
ob3.walk();
}
}