Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class mock exam question

 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is from the mock exam at http://www.geocities.com/SiliconValley/Screen/5046/ftest1.html.
The directions say to check all of the following statements which are true:
1. An inner class can have the same name as its enclosing class.
2. An instance of a non-static inner class always has an associated instance of the enclosing class.
3. An anonymous inner class is always assumed to extend Object.
According to the results, only answer #2 is correct.
But don't ALL objects extend Object?
Please advise.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class Object begets all other classes. Even if your annonymous class implements an interface, your class extends Object. So, option #3 is correct.
 
Nirmala
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephanie Grasson,
The given answer is correct. You have to read the question carefully,what it says is
An anonymous inner class is always assumed to extend
Object.
Not necessarily Always,
Anonymous class can extend to other class also.
That is why the answer is '2'.
Hope this may help to some extend.
Thanks
Nirmala
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But aren't you still extending Object in that case? It may not be the immediate parent, but it's being extended, nonetheless.
 
hemanshow
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anonymous class can:
1. either implement an interface
2. or extend an abstract class.
I think, always assumed means that if anonymous class is not made from an abstract class, it extends Object. The requirement to assume will only arise when U dunno which class it extends to (i.e. interfae).
so answers 2,3 should be right.
 
rajsim
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We should take "extend" as a specific word which relate class
and its immediate parent class as Java uses "extends" for this purpose.
[This message has been edited by rajsim (edited July 20, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic