/*Anonymous object: An object that does not have a name using one of the anonymous objects: When the object method is called only once, we can use the anonymous object to complete, the comparison is simplified. How anonymous objects are used two: an anonymous object can be passed as an argument*/classcar{String color; voidstart () {System.out.println ("The car was actuated."); }} Public classtest{ Public Static voidMain (string[] args) {//called by a famous objectCar A =NewCar (); A.start (); //Anonymous Object Invocation NewCar (). Start (); System.out.println ("======================="); NewCar (). Color = "Red";//it doesn't make sense to assign a value to an anonymous object's property. NewCar (). Start (); System.out.println ("======================="); //Pass as ArgumentPrintNewCar ()); } Static voidprint (Car c) {C.start (); }}
JAVA Anonymous Objects