Reputation: 65
I have the following problem.
class Master
{
private String name;
class Inner
{
private String name;
private void printNames()
{
System.out.println("Master.name"+"Inner.name");
}
}
}
How can I access both name fields in the inner class without changing the name?
Upvotes: 1
Views: 212
Reputation: 45339
You can use this:
System.out.println("Master.name: " + Master.this.name +
" Master.Inner.name: " + this.name);
Master.this.name
references the instance field of the outer class, Master
, from within the inner class.
Upvotes: 3