❮ Previous Next ❯

Anonymous Inner Class:

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
" />

 


❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved