???????Java??????
???????????? ???????[ 2014/12/10 11:13:45 ] ????????Java ???? ??????
????????????????ж????????????????????????????????????????????г??????????
public class Parcel8 {
// Argument must be final to use inside
// anonymous inner class:
public Destination dest(final String name?? String city) {
return new Destination(name?? city) {
private String label = name;
public String getName() {
return label;
}
};
}
public static void main(String[] args) {
Parcel8 p = new Parcel8();
Destination d = p.dest("Tanzania"?? "gz");
}
abstract class Destination {
Destination(String name?? String city) {
System.out.println(city);
}
abstract String getName();
}
}
?????????????β?city??????????б????????????????????????????Inner????????????????????????final??
??????????????????
??????????????????????????????Χ???????????????????????????????????????????????????????????????????????????“????”??????????????Χ????????????????????????????
class Egg {
private Yolk y;
protected class Yolk {
public Yolk() {
System.out.println("Egg.Yolk()");
}
}
public Egg() {
System.out.println("New Egg()");
y = new Yolk();
}
}
public class BigEgg extends Egg {
public class Yolk {
public Yolk() {
System.out.println("BigEgg.Yolk()");
}
}
public static void main(String[] args) {
new BigEgg();
}
}
?????????????
????New Egg()
????Egg.Yolk()
?????????????????????????????????????????????????????????????????????BigEgg ????????????????????“????”????Yolk??????????????п??????????????????????
?????????????????????????????Χ?????????????з?????????????仯??????????????????????????????壬?????????????????????????????????????????????????
class Egg2 {
protected class Yolk {
public Yolk() {
System.out.println("Egg2.Yolk()");
}
public void f() {
System.out.println("Egg2.Yolk.f()");
}
}
private Yolk y = new Yolk();
public Egg2() {
System.out.println("New Egg2()");
}
public void insertYolk(Yolk yy) {
y = yy;
}
public void g() {
y.f();
}
}
public class BigEgg2 extends Egg2 {
public class Yolk extends Egg2.Yolk {
public Yolk() {
System.out.println("BigEgg2.Yolk()");
}
public void f() {
System.out.println("BigEgg2.Yolk.f()");
}
}
public BigEgg2() {
insertYolk(new Yolk());
}
public static void main(String[] args) {
Egg2 e2 = new BigEgg2();
e2.g();
}
}
?????????????
????Egg2.Yolk()
????New Egg2()
????Egg2.Yolk()
????BigEgg2.Yolk()
????BigEgg2.Yolk.f()
????????BigEgg2.Yolk ???extends Egg2.Yolk ????????????????????????????е??????Egg2 ??insertYolk()???????BigEgg2 ?????????Yolk ??????????????????????y???????g()????y.f()??????????°??f()????С?????ε???Egg2.Yolk()??BigEgg2.Yolk ??????????????????????????????????????g()??????°??f()?????????
????????????????
??????????????????????????Χ????????????????????????????????????????е????????????????“?????”??Χ???????????????????????????е????в??????????????????????????????????????????????????????????????
class WithInner {
class Inner {
Inner(){
System.out.println("this is a constructor in WithInner.Inner");
};
}
}
public class InheritInner extends WithInner.Inner {
// ! InheritInner() {} // Won't compile
InheritInner(WithInner wi) {
wi.super();
System.out.println("this is a constructor in InheritInner");
}
public static void main(String[] args) {
WithInner wi = new WithInner();
InheritInner ii = new InheritInner(wi);
}
}
?????????????
????this is a constructor in WithInner.Inner
????this is a constructor in InheritInner
?????????????InheritInner ???????????????????Χ???????????????????????????????????????????????????????????????Χ?????????á??????????????????????????????
????enclosingClassReference.super();
????????????????????????????????????????
?????????????????в?????static???ε??????????????г?????
?????磺
????public class InnerClassDemo{
????int x;
????class A{
????static int a = 0;//????д????????.
????static final int b=0;//????д??????
????}
????}
????????????????????????????????????????????????????????? static class A??????????ok????????? ???????????????????????/????????????????——???????????????????????????????????????????????????????в?????徲???/????????????????
???????????????????????????static???????java?????????????г??????????ν?????????С?????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11