-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava01.java
More file actions
61 lines (49 loc) · 1.3 KB
/
Copy pathjava01.java
File metadata and controls
61 lines (49 loc) · 1.3 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
package com.other;
interface DummyInterface {
void printInfo();
}
class JavaOutter {
private String theString;
void setTheString(String str) {
this.theString = str;
}
String getAllString() {
return "abc" + theString;
}
void printSomething() {
String localString = "local string";
final String localFinalString = "local final string";
DummyInterface anon = new DummyInterface() {
@Override
public void printInfo() {
System.out.println(theString);
// local variable localString is accessed from within inner class; needs
// to be declared final
//System.out.println(localString);
System.out.println(localFinalString);
}
};
// print information from the annoymous object
anon.printInfo();
}
public static void main(String[] args) {
JavaOutter out = new JavaOutter();
JavaInner in = out.new JavaInner();
out.setTheString("the outter string");
in.printInfo();
out.printSomething();
}
class JavaInner {
// inner class cannot have static member
// unless it is const (final primitive decided at compile time)
static final String CONST_STR = "abcdefg";
JavaInner() {
this.theInnerString = "the inner string";
}
String theInnerString;
void printInfo() {
System.out.println(theString);
System.out.println(theInnerString);
}
}
}