Rahul- that's the original version of the JLS. It was written before anonymous classes were added to the language. In the
JLS second edition your quote above is modified to (Section 9.1.2):
<blockquote>While every class is an extension of class Object, there is no single interface of which all interfaces are extensions.</blockquote>
The first part of your quote has been removed since it causes confusion now. Later in section 15.9.1, "Determining the Class Being Instantiated" we have:
<blockquote>If the class instance creation expression ends in a class body, then the class being instantiated in an anonymous class. Then:
If the class instance creation expression is an unqualified class instance creation expression, then let
T be the
ClassOrInterfaceType after the <code>new</code> token. [...] If T is the name of an interface then an anonymous direct subclass of Object that implements the interface named by
T is declared.
</blockquote>
So yes,
all classes descend from Object; even anonymous classes.
As for the original question: yes, it's technically possible, but probably not in the way you mean. Jason has already shown one way; another is:
<code><pre>interface I {
void method();
}
class C implements I {
public void method() {
System.out.println("old implementation");
}
}
class
Test {
public static void main(
String[] s) {
C instance = new C() {
public void method() {
System.out.println("new implementation");
}
};
instance.method();
}
}</pre></code>
Here the anonymous class extends a class which has already implemented an interface, so we can also say that the anonymous class implements the interface.
What's not possible, however, is for an anonymous class to
directly implement an interface while also extending a class other than Object. Which may or may not be what was meant by the original question.