You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
844 B

public class Jb34_InnerClass2
{
public static void main(String[] args)
{
new Outer().method();
new Outer2().method();
}
}
/*
Ϊʲô<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD>еij<EFBFBD>Ա
<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>á<EFBFBD> <EFBFBD>ⲿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>.this
*/
class Outer
{
int num = 1;
class Inner
{
int num = 2;
void show()
{
int num = 3;
System.out.println(num); //<2F><>ӡshow<6F><77><EFBFBD><EFBFBD><EFBFBD>ڵij<DAB5>Ա
System.out.println(this.num); //<2F><>ӡ<EFBFBD>ڲ<EFBFBD><DAB2>еij<D0B5>Ա
System.out.println(Outer.this.num); //<2F><>ӡ<EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD>еij<D0B5>Ա
}
}
void method()
{
new Inner().show();
}
}
//JDK1.7֮ǰ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ھֲ<EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>ܷ<EFBFBD><EFBFBD>ʾֲ<EFBFBD><EFBFBD>б<EFBFBD>final<EFBFBD><EFBFBD><EFBFBD>εľֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//JDK1.8ʱ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ھֲ<EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><EFBFBD>ʾֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class Outer2
{
int num = 1;
void method()
{
int x = 2; //<2F>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>x
class Inner2
{
void show()
{
System.out.println("show"+x);
}
}
Inner2 in = new Inner2();
in.show();
}
}