Skip to content

Latest commit

 

History

History
34 lines (29 loc) · 753 Bytes

File metadata and controls

34 lines (29 loc) · 753 Bytes
layout default
title Anonymous Inner Class
parent Inner Class
nav_order 2

Java Anonymous inner class

A class that have no name is known as anonymous inner class in java. It should be used if you have to override method of class or interface. Java Anonymous inner class can be created by two ways:

1- Class (may be abstract or concrete).
2- Interface

Java anonymous inner class example using class
    abstract class Person{  
      abstract void eat();  
    }  
    class TestAnonymousInner{  
     public static void main(String args[]){  
      Person p=new Person(){  
      void eat(){System.out.println("nice fruits");}  
      };  
      p.eat();  
     }  
    }  

Output

nice fruits