This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
In Java we have a concept of Anonymous objects like
new Circle(); // (A)
System.out.println("Area is " + new Circle(5).getArea()); // (B)
In both these cases the constructor is called and hence the object should be created BUT as no handle/reference variable is attached to this one then it must be picked by the Garbage Collector.
And if this is the case then how can one really print the area as in the above e.g (B)
In many cases anonymous objects are anonymous only to you. For example, in:
both the anonymous Thread and anonymous MyRunnable are very alive
and active until the run() method completes. Also, they are given names
in the constructor parameter list.