forked from java-tester-x/thinking_in_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestExtends.java
More file actions
46 lines (34 loc) · 728 Bytes
/
TestExtends.java
File metadata and controls
46 lines (34 loc) · 728 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
class A {
protected int x = 1;
public A() {
System.out.println("A(): x = " + x);
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
}
class B extends A {
protected int x = 2;
public int getX() {
return x;
}
public B() {
super();
System.out.println("B(): x = " + x);
}
}
public class TestExtends extends B {
private int x = 0;
public TestExtends() {
super();
System.out.println("TestExtends(): x = " + x);
}
public static void main (String[] args)
{
TestExtends t = new TestExtends();
System.out.println("main(): x = " + t.x);
}
}