Which three code fragments, added individually at line 26, produce the output 100? (Choose three.)
class Inner {
private int x;
public void setX(int x) {this.x = x;}
public int getX(){return x;}
}
class Outer{
private Inner y;
public void setY(Inner y) {this.y = y;}
public Inner getY(){return y;}
}
public class Gamma {
public static void main(String[] args){
Outer o = new Outer();
Inner i = new Inner();
int n = 10;
i.setX(n);
o.setY(i);
**// Line 26**
System.out.println(o.getY().getX());
}
}
This question is from SCJP
A.
n = 100;
B.
i.setX( 100 );
C.
o.getY().setX( 100 );
D.
i = new Inner(); i.setX( 100 );
E.
o.setY( i );
i = new Inner();
i.setX( 100 );
F.
i = new Inner();
i.setX( 100 );
o.setY( i );
ANSWER IS BCF
I understand B and C but i dont understand F. If i use D option why its giving me 10 as output. I want to know what is happening when i use option D.
Ure replies are more than welcomed
Thanks in advance