Is there any functional difference?
Both will behave in the same way.
The second option doesn't allow you to reuse that instance again. It may be convenient and concise in one-line return statements (for instance, consider the builder pattern where each constructing method returns a half-initialised instance):
return new Builder().a().b().build();
or if an object was created only to perform a defined action once.
What will be the reference of a new object in method-2?
It is no longer exist (more precisely, we don't have access to it) unless the doThis
returns this
which you could be able to put in a variable after method execution.
Can I say that method-2 is an improper way of calling a non-static method?
No. Why should we create a variable if this variable will never be used afterwards?
new A()
makes a newA
(becausenew A()
anda
are not the same object) – DraffA a1 = new A();
. Unless code usesa1
afterwards, they're equivalent - assigning the value to a local variable which isn't otherwise used won't make any difference. – Chaco