Skip to content

Latest commit

 

History

History
34 lines (29 loc) · 753 Bytes

AnonymousInnerClass.md

File metadata and controls

34 lines (29 loc) · 753 Bytes
layout title parent nav_order
default
Anonymous Inner Class
Inner Class
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