You can use the instance initialization section: new AbstractAction() { { //initialization code goes here } actionPerformed(ActionEvent event) { … } } Show activity on this post. Or you can just access the variables of the outer class from the inner class.
Read moreCan anonymous inner class have constructor?
Since anonymous inner class has no name, an anonymous inner class cannot have an explicit constructor in Java .
Read moreWhat is the difference between inner class and anonymous class?
A local inner class consists of a class declared within a method, whereas an anonymous class is declared when an instance is created . So the anonymous class is created on the fly or during program execution.
Read moreWhat is anonymous inner class Mcq?
Explanation: Anonymous inner classes are the same as the local classes except that they don’t have any name . The main use of it is to override methods of classes or interfaces.
Read moreHow do you make an anonymous class constructor?
You can’t declare a constructor for an anonymous class , because the name for a constructor must be the same as the name of the class. And since the class in question has no name, you can’t declare a constructor for the class.
Read moreHow do you define anonymous inner class?
Java anonymous inner class is an inner class without a name and for which only a single object is created . An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overloading methods of a class or interface, without having to actually subclass a class.
Read moreWhat is the inner and anonymous inner class?
Java anonymous inner class is an inner class without a name and for which only a single object is created . An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overloading methods of a class or interface, without having to actually subclass a class.
Read more