Janki Shah wrote:How can I access inner class ten and it's integer variable x = 11 ?
CertPal Test
hi friend,
i have tried the pgm what you have posted here. i have cleared your problem. check the below program:
public class one
{
final Integer y=10;
two t=new two();
public class two//class inside class one
{
final int x;
public two() //constructor of class two
{
x = 10;
class ten //sub-class in class two
{
ten(){
int x = 11;
System.out.println("inside class ten"+x);
}
}
ten t=new ten();
System.out.println("inside class two"+x);
}
}
public int get() // method in class one
{
System.out.println("below two stmts output is class one inside get() method");
two two2 = new two();
return two2.x;
}
public static void main(String [] args)
{
one one = new one();
System.out.println("sum of two no.s is:"+(one.y + one.get()));
}
}
output is:
inside class ten11
inside class two10
below two stmts is of class one inside get() method
inside class ten11
inside class two10
sum of two no.s is:20