Wanted to know how is that different from this new way i.e. new classname().methodname()
This way of method calling in OOP languages is called Method chaining.
When bike1() method is executed then this anonymous object of Ddemos1 will be eligible for garbage collection but we don't know when precisely it will be GC.
krishnadhar Mellacheruvu wrote:When the method scope ends the object is distroyed
how is this different from a normal object? is it that the normal object that we create can be used multiple times but the anonymous object can be used only once. Correct me if am wrong.
I don't think so, it's general term. There is no such concept of anonymous object like anonymous class which is a concept of inner classes which further divides in local class and anonymous class. So anonymous object IMO means just an object whose reference is not stored for further use.
can you clarify another doubt of mine which is like, does java have the concept of anonymous object's though i have heard about anonymous classes.