-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFrog.java
More file actions
124 lines (92 loc) · 2.81 KB
/
Frog.java
File metadata and controls
124 lines (92 loc) · 2.81 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package polymorphism;
import java.io.PrintStream;
class Cyrillic {
public static void println(String s)
{
try {
PrintStream ps = new PrintStream(System.out, true, "UTF-8");
ps.println(s);
}
catch (java.io.UnsupportedEncodingException e) {
System.out.println("Error");
}
}
}
class Characteristic {
private String s;
Characteristic(String s) {
this.s = s;
// System.out.println("Create Characteristic " + s);
Cyrillic.println("Создаем Characteristic " + s);
}
protected void dispose() {
// System.out.println("Dispose Characteristic " + s);
Cyrillic.println("Завершаем Characteristic " + s);
}
}
class Description {
private String s;
Description(String s) {
this.s = s;
Cyrillic.println("Создаем Description " + s);
}
protected void dispose() {
Cyrillic.println("Завершаем Description " + s);
}
}
class LivingCreature {
private Characteristic p = new Characteristic("живое существо");
private Description t = new Description("обычное живое существо");
LivingCreature() {
System.out.println("LivingCreature()");
}
protected void dispose() {
System.out.println("dispose() in LivingCreature");
t.dispose();
p.dispose();
}
}
class Animal extends LivingCreature {
private Characteristic p = new Characteristic("имеет сердце");
private Description t = new Description("животное, не растение");
Animal() {
System.out.println("Animal()");
}
protected void dispose() {
System.out.println("dispose() in Animal");
t.dispose();
p.dispose();
super.dispose();
}
}
class Amphibian extends Animal {
private Characteristic p = new Characteristic("может жить в воде");
private Description t = new Description("и в воде, и на земле");
Amphibian() {
System.out.println("Amphibian()");
}
protected void dispose() {
System.out.println("dispose() in Amphibian");
t.dispose();
p.dispose();
super.dispose();
}
}
public class Frog extends Amphibian {
private Characteristic p = new Characteristic("квакает");
private Description t = new Description("ест жуков");
Frog() {
System.out.println("Frog()");
}
protected void dispose() {
System.out.println("dispose() in Frog");
t.dispose();
p.dispose();
super.dispose();
}
public static void main(String[] args) {
Frog frog = new Frog();
System.out.println("Goodbye!");
frog.dispose();
}
}