Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

Anonymous Object

An object that does not have reference or name is called anonymous object.
It can be used only once.
After its one time use, it is ready for garbage collection.

Example

class Circle 
{
     int radius=5;
	
     public void calculateArea()
     {
         System.out.println("Area of Circle :: "+3.14*radius*radius);
     }
	
     public static void main(String args[])
     {
         new Circle().calculateArea(); // Anonymous Object created &
                                       // used to call method
     }
}

Output

Area of Circle :: 78.5

 

Leave a reply