wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner classes must extend? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner classes must extend?" Watch "Inner classes must extend?" New topic
Author

Inner classes must extend?

Christoffer Jeffson
Greenhorn

Joined: May 22, 2002
Posts: 5
Just did John Hunt's Mock exam and stumbled over this:

The correct answer is C. But must inner classes really extend any class or interface?
Robert Ziel
Greenhorn

Joined: Apr 22, 2002
Posts: 28
Hi Cristoffer,
an inner class my extend another class or implement an interface
or nothing (implicit Object)
robert
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Actually, I find the wording to be rather innacurate. The question states, "What class must an inner class extend?" For one thing, interfaces aren't classes and a class doesn't extend an interface, it implements the interface. Only interfaces can extend interfaces. So, the mention of interfaces is rather hokey with the way the question is worded.
Any class that you create in Java will necessarily extend some object. You might specify a class that it extends or, if you don't, your class will implicitly extend Object. Therefore, every inner class, like any other class, must extend some class. Of course, that can be any class you like.
Even though I dislike the wording, an inner class can also implement any interface (or number of interfaces), but it is not required to do so.
I hope that helps,
Corey


SCJP Tipline, etc.
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
Is that true? I thought Inner class can extend one class or implement only one interface. Also, I assumed, if it is not extending or implementing, Object class is extended.


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
An inner class can extend another AND implement many interfaces. An anonymous class only can extend another OR implement an interface.


SCJP2. Please Indent your code using UBB Code
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Thiru Thangavelu:
Is that true? I thought Inner class can extend one class or implement only one interface. Also, I assumed, if it is not extending or implementing, Object class is extended.

Perhaps you're thinking of an anonymous class. When you use the following syntax to create an anonymous class:

You only have room to identify a single class or interface. However, if you make a simple inner class, like this:

You can see here that I can extend a class and also implement as many interfaces as I'd like. Of course, as with any class, if no class is extended, the Object class is extended implicitly.
I hope that helps,
Corey
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner classes must extend?