• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inner class mock exam question

 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic