The class which is declared without name is called Anonymous Inner Class.

Let's see following example for better clarity.

Here, i have presented two examples :
1.Normal Interface approach
2.Using Anonymous inner class

Normal Interface Approach

package java8s;

interface Transaction
{
   public void withDraw(int amt);
}

class A implements Transaction
{
   public void withDraw(int amt)
   {
       System.out.println("amount withdrawn is"+amt);
   }
}
public class Example {

   public static void main(String[] args) {
      
       A ob1=new A();  
      
       ob1.withDraw(15000);
      
   }

}

Using Anonymous Inner Class

package java8s;

interface Transaction
{
   public void withDraw(int amt);
}

 

public class Example {

   public static void main(String[] args) {
      
       Transaction ob1=new Transaction()   //Anonymous Inner Class
       {
          public void withDraw(int amt)
          {
              System.out.println("amount withdrawn is"+amt);
          }
       };
      
       ob1.withDraw(15000);
      
   }

}

Output
anonymous inner class
" />

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment