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 classes be private?
Also, like local classes, anonymous classes cannot be public, private, protected, or static .
Read moreCan Java inner class be private?
Unlike a class, an inner class can be private and once you declare an inner class private, it cannot be accessed from an object outside the class. Following is the program to create an inner class and access it.
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 moreHow do you make an anonymous class?
The anonymous class expression consists of the following:
Read moreWhat are anonymous inner classes?
It 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 overriding methods of a class or interface, without having to actually subclass a class.15 Ara 2021
Read moreWhat constructs an anonymous inner class instance?
Which constructs an anonymous inner class instance? Runnable r = new Runnable() { };
Read more