-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathParcel11.java
More file actions
73 lines (55 loc) · 1.58 KB
/
Parcel11.java
File metadata and controls
73 lines (55 loc) · 1.58 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
package innerclasses;
/**
* RUN:
* javac innerclasses/Parcel11.java && java innerclasses.Parcel11
* OUTPUT:
* ParcelDestination.f()
*/
public class Parcel11 {
private static class ParcelContents implements Contents
{
private int i = 11;
public int value() { return i; }
}
protected static class ParcelDestination implements Destination
{
private String label;
private ParcelDestination(String whereTo) {
label = whereTo;
}
public String readLabel() { return label; }
public static void f() {
System.out.println("ParcelDestination.f()");
}
static int x = 10;
static class AnotherLevel
{
public static void f() {
System.out.println("ParcelDestination.AnotherLevel.f()");
}
static int x = 9;
}
}
public static Destination destination(String s) {
return new ParcelDestination(s);
}
public static Contents contents() {
return new ParcelContents();
}
public static void main(String[] args) {
Contents c = contents();
Destination d = destination("Tasmania");
// Error when try:
//
// d.f();
//
// innerclasses\Parcel11.java:58: error: cannot find symbol
// d.f();
// ^
// symbol: method f()
// location: variable d of type Destination
// 1 error
// It's ok !
((ParcelDestination) d).f();
}
}