hi, i got it from whizlabs practice exam3.
class Myouter
{
private class Myinner
{
float f()
{
return 1.3;
}
}
Myinner getIt()
{
return new Myinner();
}
}
class Outside
{
public static void main(
String args[])
{
Myouter outer=new Myouter();
System.out.println(outer.getIt().f());
}
}
Answer
oes not compile since the f() returns double value. This is ok. Thay have given additional information on inner class as following.
Myinner is a private class,so you cannot access it directly from ouside code, for eg, new Myouter().new Myinner().f(); will give compile error.
but in the given program we get the inner class object reference using a method of the outer enclosing class,which is allowed. since the f() is ot private you can access it using obtained reference.
Now.. i tried this program with correct return value of f().but it gives error that f() in Myouter.Myinner is defined in an inaccessible class or interface.
System.out.println(outer.getIt().f());//error.
please someone clear this. if the above statement is true, why this error?
Thanks in advance
Preetha