The -non-static- inner class has a full accessibility to all regular members of the outer class. but there is another way to access these members using the (outerClass.this.regularMember).., have a look on the following code:
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();
}
}
}
- Could you please explain me if there would be any practical difference between using
Car.this.move();
andmove();
- How can you explain this syntax of Car.this. , cause as far as I understand this here refers to an object of Type Engine but then if I used another reference say by doing
Engine smallEngine = new Engine();
then this keyword is not substitutable by smallEngine .