Which statements concerning the relation between a non-static inner class and its outer class instances are true?
b.Member variables of the outer instance can always be referred to using only the variable name within the inner instance.
The answer b is correct according to the following program.
class Outer{
private int x=7;
class Inner{
public void seeOuter(){
system.out.println("Outer x is" +x);
}
}
}
About Question com.enthuware.ets.scjp.v6.2.354 :
Moderator: admin
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.354 :
What if Inner also has int x?
Re: About Question com.enthuware.ets.scjp.v6.2.354 :
No Inner doesn't have x...
This program is from K & B book....
This program is from K & B book....
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.354 :
I realize that in this code Inner doesn't have x. But what if it had? Can you access outer class's x directly? No, you cannot. Hence, the option "Member variables of the outer instance can always be referred to using only the variable name within the inner instance." is not correct.
The explanation provided with this option also makes it clear that it is possible only if that variable is not shadowed by another variable in the inner class.
The explanation provided with this option also makes it clear that it is possible only if that variable is not shadowed by another variable in the inner class.
-
- Posts: 50
- Joined: Sun Nov 10, 2013 4:39 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.354 :
This discussion is showing up with question 6.2.35. Wrong link
Who is online
Users browsing this forum: No registered users and 6 guests