How can you create anonymous class?

1 answer

Answer

1095668

2026-04-02 15:30

+ Follow

Java
Java

In Java, an anonymous class can be created by instantiating a class or interface directly at the point of declaration without giving it a name. This is typically done using the new keyWord followed by the class or interface type and providing an implementation of its methods. For example:

<code class="language-Java">Runnable runnable = new Runnable() {

@Override public void run() { System.out.println("Running in an anonymous class"); } };

</code>

Here, Runnable is implemented as an anonymous class to define the run method.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.