• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Inner class extends

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was giving a mock on ww.4test.com, there I found this question.

What class must an inner class extend:

1.The top level class
2.The Object class
3.Any class or interface
4.It must extend an interface

The answer given is 3, but I think answer should be 2.

Could someone explain this example question.

Thanks
Kaps
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that none of those answers are correct.

1 is not true. That would mean than an inner class can only subclass the class that it is in.

2 is not correct because because you can extend any class, not just the Object class.

3 is not correct because you cannot extend an interface, the are implemented.

4 is not correct for the same reason as number 3.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose answer 2 is the best answer among those given, but I'd think that an inner class:
1) can extend a class
2) or can implement one or more interfaces
3) or can extend a class and implement one or more interfaces
4) or can simply implicitly extend Object
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the answer should be 2. The only class an inner class "must" extend is Object.
 
kapil munjal
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your response...I was also of the same opinion that option 2 is correct.

Well, the exam seems to be quite old, may be they are not interested in updating their site.

kaps
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the question is What class must an inner class extend? instead of What class can an inner class extend?

The answer is NONE of the above
Otherwise, the answer should be #3 as i understaning. Correct me if my answer is not correct
thanx
 
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai Le,
Class cannot extend interface they implement them.So answer 3 is not correct choice
[ November 18, 2004: Message edited by: Jay Pawar ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what is meant by "must." All classes are implicitly derived from Object; so in that sense, an inner class "must" extend Object. Of course, an inner class is not required to explicitly extend anything (although it certainly can), and it does not implicitly extend the enclosing class (although it can do so explicitly). So considering the word "must" along with the options provided, implicit extension of Object is the only interpretation that makes sense.
[ November 18, 2004: Message edited by: marc weber ]
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have seen this question on other mock exams and answear is given same - that is 3.Any class or interface

This is what i found: Please correct if i am wrong.

Meaning of must looks like inner class declaration must use extend keyword in this case.

So, considering above point, option 1 is correct, inner class can extend top level class.
option 2 is correct inner class can extend object class.
option 3 is wrong as class can not extend interface, it has to be implemented.
option 4 is wrong for same reason as above.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitin Bhagwat:
... Meaning of must looks like inner class declaration must use extend keyword in this case...


Respectfully, I have to disagree, as I don't see how the following can be rationalized:

Q: What class must an inner class extend?
A: The top level class.

Asking what an inner class "can" extend is quite different than asking what it "must" extend. If we interpret the question to mean explicit use of the "extends" keyword, then none of the options are correct because an inner class is not required to explicitly extend anything. On the other hand, if we interpret the question to mean implicit inheritance, then Object is the only option that's consistent with "must."
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic