62,614
社区成员
发帖
与我相关
我的任务
分享
package csdn;
import java.util.ArrayList;
import java.util.HashMap;
public class Father {
int id=1;
class Son {
int id;
void changeId() {
this.id = 10; //这里引用是指s
Father.this.id = 20;/这里指的是f引用!
}
}
public static void main(String[] args) {
Father f = new Father();
Father.Son s = f.new Son();
s.changeId();
System.out.println(s.id);
System.out.println(f.id);
}
}
public class Father {
int id = 1;
class Son {
int id = 2;
void changeId() {
id = 10;
System.out.println("Son's = " + id);
Father.this.id = 20;
System.out.println("Father's id = " + Father.this.id);
}
}
public void show(){
Son s = new Son();
s.changeId();
}
public static void main(String[] args){
Father f = new Father();
f.show();
}
}