Anonymous classes must extend or implement something, like any other Java class, even if it's just java.lang.Object.

For example:

Runnable r = new Runnable() {
   public void run() { ... }
};

Here, r is an object of an anonymous class which implements Runnable.

An anonymous class can extend another class using the same syntax:

SomeClass x = new SomeClass() {
   ...
};

What you can't do is implement more than one interface. You need a named class to do that. Neither an anonymous inner class, nor a named class, however, can extend more than one class.

Answer from skaffman on Stack Overflow
🌐
Programiz
programiz.com › java-programming › anonymous-class
Java Anonymous Class
Anonymous classes usually extend subclasses or implement interfaces.
People also ask

Are there any limitations when using anonymous classes with Java's functional interfaces?
Although anonymous classes can implement functional interfaces, they lack the conciseness of lambda expressions. Lambdas are preferred for functional interfaces because they provide a cleaner and more compact syntax, whereas anonymous classes tend to introduce unnecessary boilerplate.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › anonymous class in java
A Complete Guide to Anonymous Class in Java with Examples
Can an anonymous class access private members of the enclosing class?
Yes, anonymous classes can access the private members of the enclosing class, as long as they are within the same scope. This feature is helpful when you need to create a concise class implementation that interacts closely with the enclosing class.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › anonymous class in java
A Complete Guide to Anonymous Class in Java with Examples
How can I manage exceptions effectively within an anonymous class?
Managing exceptions inside an anonymous class is similar to handling them in regular classes. You can use try-catch blocks to handle exceptions, but be cautious not to overload the anonymous class with too many complex error-handling logic, as this can make it harder to debug.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › anonymous class in java
A Complete Guide to Anonymous Class in Java with Examples
🌐
Baeldung
baeldung.com › home › java › core java › anonymous classes in java
Anonymous Classes in Java | Baeldung
June 11, 2024 - For the most precise and updated information, we may always look at the Java Language Specification. The syntax of anonymous classes does not allow us to make them implement multiple interfaces. During construction, there might exist exactly one instance of an anonymous class. Therefore, they can never be abstract. Since they have no name, we can’t extend them.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › anonymous class in java
A Complete Guide to Anonymous Class in Java with Examples
March 6, 2025 - Anonymous classes can also extend abstract classes to provide implementations for their abstract methods directly, without needing to define a full class.
🌐
W3Schools
w3schools.com › Java › java_anonymous.asp
Java Anonymous Class
You often use anonymous classes to override methods of an existing class or interface, without writing a separate class file. Here, we create an anonymous class that extends another class ...
🌐
Edureka
edureka.co › blog › anonymous-class-in-java
How to Implement Anonymous Class in Java | Edureka
June 17, 2021 - We can create an anonymous inner class by extending other class, suppose we have to create a thread by using Thread class we can create an anonymous inner class instead of creating a separate class.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › anonymous class in java
Anonymous Class in Java - Scaler Topics
April 8, 2024 - There can be 2 types of anonymous classes in Java: An anonymous class that extends a class.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java
Anonymous Class Java Example - Java Code Geeks
October 15, 2020 - A normal class can implement any number of interfaces but an anonymous inner class can implement only one interface at a time. A regular class can extend a class and implement any number of interface simultaneously.
🌐
Scientech Easy
scientecheasy.com › home › blog › anonymous inner class in java
Anonymous Inner Class in Java - Scientech Easy
January 18, 2026 - 2. A normal Java class can extend a class and can implement any number of interfaces simultaneously but an anonymous inner class can extend a class or can implement an interface but not both simultaneously.
🌐
zentut
zentut.com › home › java tutorial › java anonymous class
Java Anonymous Class
April 22, 2024 - In Java, an anonymous class is a class that has no name that extends an existing class or implements an interface.
🌐
Coderanch
coderanch.com › t › 517066 › certification › Anonymous-class-extends-implements
Anonymous Inner class extends/implements [Solved] (OCPJP forum at Coderanch)
November 13, 2010 - EXPLANATION: The syntax of an anonymous inner class allows for only one named type after the new, and that type must be either a single interface (in which case the anonymous class implements that one interface) or a single class (in which case the anonymous class extends that one class).
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › anonymous class in java
Anonymous Class in Java | How to Generate Files in Anonymous Class?
March 27, 2023 - A normal class extends an abstract class and implements an interface at one time, but the anonymous inner class can only extend an abstract class or implement an interface at a single.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
w3resource
w3resource.com › java-exercises › nested-classes › java-nested-classes-exercise-8.php
Java Anonymous Class Implementing Abstract Class Example
In this exercise, an anonymous class extends the abstract class Animal and provides an implementation for the "makeSound()" method. This allows for quick and concise definition of a subclass and its methods, making the code more readable and ...