-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPolyConstructors.java
More file actions
51 lines (39 loc) · 965 Bytes
/
PolyConstructors.java
File metadata and controls
51 lines (39 loc) · 965 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
40
41
42
43
44
45
46
47
48
49
50
51
package polymorphism;
/**
* RUN:
*
* javac polymorphism/PolyConstructors.java && java polymorphism.PolyConstructors
*
* OUTPUT:
*
* Glyph() before invoking draw()
* RoundGlyph.draw().radius = 0
* Glyph() after invoking draw()
* RoundGlyph.RoundGlyph().radius = 5
*
*/
class Glyph {
void draw() {
System.out.println("Glyph.draw()");
}
Glyph() {
System.out.println("Glyph() before invoking draw()");
draw();
System.out.println("Glyph() after invoking draw()");
}
}
class RoundGlyph extends Glyph {
private int radius = 1;
void draw() {
System.out.println("RoundGlyph.draw().radius = " + radius);
}
RoundGlyph(int r) {
radius = r;
System.out.println("RoundGlyph.RoundGlyph().radius = " + radius);
}
}
public class PolyConstructors {
public static void main(String[] args) {
new RoundGlyph(5);
}
}