Gaurang Pathare

Greenhorn
+ Follow
since Oct 31, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gaurang Pathare

Originally posted by Burkhard Hassel:
Hi Prashanth,
you wrote:
My guess is all 3 objects as after local method,all references are set to null??
That's what I though also, but it is not what the creators of these tests want to hear. At that very point, the method is not yet over (after a millisecond, it will be). But they're wanting us to really see where the references point to. And count the objects that are dereferenced at that point.
I guess, that example is from you?

Here is my solution, I hope it is correct:




I'm not ready with the counting yet, maybe tomorrow.

Yours,
Bu.


IMO since the compiler is still in the main method only 2 objects will be eligible for gc, the once with the reference = null, i.e r2 and r4

may be this will help

[CODE]
class Rubbish {
public static void main(String [] args) {
Rubbish r1 = new Rubbish();
Rubbish r2 = new Rubbish();
Rubbish r3 = new Rubbish();
Rubbish r4 = r2;
Rubbish r5 = r4;
r2 = null;
r4 = r2;
r1 = r5;
// do stuff

System.out.println(r1);
System.out.println(r2);
System.out.println(r3);
System.out.println(r4);
System.out.println(r5);
}
}
[/CODE}

OUTPUT ->

Rubbish@7d772e
null
Rubbish@11b86e7
null
Rubbish@7d772e

--------

r2 = null
and since r4 = r2, even r4 = null,
but r5 will still refer to the rubbish object from line 7, and hence r1 will aslo refer to same object.

Originally posted by sanjib sanju:
The disscussion here can solve the Questions like:
1) Although abstract class are not supposed to be instantiated then why to declare a constructor?
2) Does compiler inserts default constructor to the abstract class?

and so on...
Thanks
Sanjeev Singh



Hey guys but don't you think the questiion still remains unanswered,
Why do we need a constructor for an abstract class.

Agreeded in the above example we need a constructor in the abstarct class as it extends from other concrete class, but why would we need it when abstarct class is the parent class, since we ain't ever going to create an insatance of that abstratc class.
Or is that the coplier will not insert a default constructor when abstract class is the parent class.