Java-Anonymous Object
An anonymous object
new Car().num = 5; attribute has no meaning
new Car().run(); method makes sense
Even using properties of anonymous objects doesn’t make sense
And it makes sense to use its methods
How to use:
When the method on the object is called only once, it can be done with an anonymous object, which is simpler
If you call a member of an object, you must give the object a name
Two Below are two pictures
non-anonymous object
Copyright statement: This article is an original article of the blogger, and shall not be reproduced without the permission of the blogger.
Java-Anonymous Object