What is an Anonynous inner class? - Java

What is an Anonymous inner class? Explain with an example

Anonymous Inner Classes

An inner class without a name. It allows the declaration of the class, creation of the object and execution of the methods in it at one shot. The typical use of inner class is widely used in GUI event handling.

For example
button.addActionListener(new ActionListener()
   // The way of using Anonymous Inner class
   public void actionPerformed(ActionEvent e)
       System.out.println("The button was pressed!");
In the above code snippet, there a definition of a new class while invoking another method. By utilizing an anonymous inner class, the hard coding of defining a separate class and its methods and invoking them by creating an exclusive object explicitly, is reduced to almost a single line within its containing class.
What is object deep copy and shallow copy? - Java
In deep copy the copy operations would respect the semantics of the object. For example, copying an object along with the objects to which it refers to...
What is dynamic variable in java and where do we use them?
The variables that are initialized at run time is called as dynamic variable...
Explain the advantages of JTA over JTS
Java Transaction API is simple and more flexible to use. There are two levels in JTA API...
Post your comment