This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
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
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
posted
0
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
posted
0
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.