Anonymous Classes in Java (Part 10)
Pre-requisites:- Inner Classes , Interface , Method Overridding Anonymous Classes It is an inner class without a name and for objects cannot be created. An anonymous inner class can be useful when making an instance of an object with certain extras such as overriding methods of a class or interface, without having to actually create a subclass for it. Anonymous inner classes are useful in writing implementation classes for listener interfaces in graphical user interface programming (GUI) . Syntax:- Class_name [obj name] = new Class_name() { //anonymous class (child class) //override methods of parent classes / interfaces / abstract classes }; Declaring an Anonymous Classes An Anonymous class in Java can be created by two ways: 1. By Classes (Abstract or Normal) Eg:- class Machine { public void start () { System.out.println(" Parent Machine Starting. "); } } public class MyClass { public stati...