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
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
Joined: Dec 20, 2001
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