Question ID :953582008890
What will be the result of attempting to compile and run the following code?
public class Nesting
{
public static void main(
String args[])
{
B.C obj = new B( ).new C( );
}
}
class A
{
char c;
A(char c) { this.c = c; }
}
class B extends A
{
char c = 'a';
B( ) { super('b'); }
class C extends A
{
char c = 'c';
C( )
{
super('d');
System.out.println(B.this.c);
System.out.println(C.this.c);
System.out.println(super.c);
}
}
}
Options :
1)It will not compile
2)It will give Runtime error
3) The program will compile without error and print a,c and d in that order when run
4) The program will compile without error and print a,b and d in that order when run
5) The program will compile without error and print b, c and a in that order when run
Ans :3)
I tried running the program, it gave me answer 3).
but i cant understand such an output.Can anyone explain me ??
Sonir