-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitrfce.java
More file actions
111 lines (99 loc) · 2.19 KB
/
Copy pathitrfce.java
File metadata and controls
111 lines (99 loc) · 2.19 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/************************************************************************************
* File :Interface.java
* Author :Prapanch j
* Description :Java Program Use the Concept of Interface
* Version :1.0
* Date :10/11/23
***********************************************************************************/
package javalab;
public class itrfce {
public static void main(String[] args) {
Fish d = new Fish("Mimi");
Cat c = new Cat("Fluffy");
Animal e = new Spider();
Pet p = new Cat();
System.out.println("CAT");
System.out.println("This cat's name "+c.getname());
c.walk();
c.eat();
c.setname("Moose");
System.out.println("This cat's name "+p.getname());
System.out.println("SPIDER");
e.walk();
e.eat();
System.out.println("FISH");
System.out.println("This fish's name "+d.getname());
d.walk();
d.eat();
d.setname("Momo");
System.out.println("This fish's name "+d.getname());
}
}
abstract class Animal {
protected int legs;
protected Animal(int legs) {
this.legs = legs;
}
public abstract void eat();
public void walk() {
System.out.println("This animals walk by "+this.legs+" legs");
}
}
class Spider extends Animal {
public Spider() {
super(8);
}
public void eat() {
System.out.println("Spider eat insect");
}
}
interface Pet {
public String getname();
public void setname(String name);
public void play();
}
class Cat extends Animal implements Pet{
private String catname;
public Cat(String name) {
super(4);
this.catname=name;
}
public Cat() {
this("Moose");
}
public String getname() {
return this.catname;
}
public void setname(String name) {
this.catname = name;
}
public void play() {
}
public void eat() {
System.out.println("Cat eat Fishes");
}
}
class Fish extends Animal implements Pet{
String fishname;
public Fish(String name) {
super(0);
this.fishname=name;
}
public Fish() {
this("Momo");
}
public void walk() {
System.out.println("Fish has no legs");
}
public String getname() {
return this.fishname;
}
public void setname(String name) {
this.fishname = name;
}
public void play() {
}
public void eat() {
System.out.println("Fishes eat Plants");
}
}