Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused

 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody explain me why the answer is B,SuperB,A,SuperA
This is a question in Dans mock exam and i guess theres been some error here in code as i feel line 5 doesn't make any sense

 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,
In line 6 the inner class B and it's enclosing class
A are instantiated and m1() is invoked immediately.
In line 2 this refers to the instance of the inner
class; in line 3 super refers to the superclass (SuperB)
of the inner class and in particular to the value of s1;
in line 4 A.this.s1 refers to the instance of the enclosing
class A and in particular the value of s1.
And coming back to your question line 5 refers to the
superclass of the enclosing class A (SuperA) and in
particular to the value of s1.
Instances of class A are always instances of (instanceof)
class A or SuperA.
class B has no other relationship with A than being
it inner class. With this I mean that it doesn't
extend in any way class A. And can't be an instanceof
A.

Was I clear? Best Regards,

Gian Franco Casula
p.s. the code compiles with no hitches
[ February 26, 2004: Message edited by: Gian Franco Casula ]
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx,
I missed that it was an innerclass........oversight
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic