-non-static- 内部类对外部类的所有常规成员具有完全可访问性。但是还有另一种方法可以使用 (outerClass.this.regularMember).. 访问这些成员,请查看以下代码:
public class Car {
int x = 3;
public static int hp =6;
public void move()
{
System.out.println(hp);
}
public class Engine{
public int hp =5;
public int capacity;
public void start()
{
Car.this.move(); // or we can use only move();
}
}
}
- 您能否解释一下使用
Car.this.move();
和之间是否有任何实际区别move();
- 你如何解释Car.this 的这种语法。,因为据我了解,这里指的是 Type Engine 的一个对象,但是如果我使用另一个引用说这样做,
Engine smallEngine = new Engine();
那么 这个关键字不能被smallEngine替代。