-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest9
66 lines (53 loc) · 967 Bytes
/
test9
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
class Shape {
function area() {
return 0;
}
function largerThan(s) {
return this.area() > s.area();
}
}
class Rectangle extends Shape {
var height;
var width;
function setHeight(h) {
height = h;
}
function setWidth(w) {
width = w;
}
function getHeight() {
return height;
}
function getWidth() {
return width;
}
function area() {
return getWidth() * getHeight();
}
}
class Square extends Rectangle {
function setSize(size) {
super.setWidth(size);
}
function getHeight() {
return super.getWidth();
}
function setHeight(h) {
super.setWidth(h);
}
static function main() {
var s1 = new Square();
var s2 = new Rectangle();
var s3 = new Square();
s1.setSize(5);
s2.setHeight(8);
s2.setWidth(4);
s3.setWidth(3);
var max = s1;
if (s2.largerThan(max))
max = s2;
if (s3.largerThan(max))
max = s3;
return max.area();
}
}