Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Karina K patni   on Aug 04 In Java Category.

  
Question Answered By: Kay Rodriguez   on Aug 04


This code does compile and run. I've added some more features to the three
classes so that you can actually determine which method is being called. I
personally didn't think that "class C extends A.B" would extend class  B, but
it does. I didn't realize that you could extend an inner class in this
manner. It does show that the a.super() call  is not needed and does not
have an effect.

-Fred E Golder

public class A
{
int value = 1;
A()
{
value *= 10;
System.out.println("in A constructor");
}
int test() { return  ++value; }
int show() { return value; }

class B
{
int test() { return value/5; }
}

public static void main(String[] args)
{
A aaa = new A(); //expect value = 10
System.out.println("value is "+aaa.show()); //expect value =10
System.out.println("Test returns"+aaa.test()); //expect value = 11
C ccc = new C(aaa);
}
}

class C extends A.B
{
C(A a)
{
a.super();//expect there is no effect & optimized out of byte code
System.out.println("in C constructor");
System.out.println("Test returns"+a.test()); //expect value = 12
System.out.println("Test returns"+test()); //expect value = 2
}
}

Share: 

 

This Question has 18 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Inner class inherit question Or get search suggestion and latest updates.


Tagged: