• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I think D is right, but someone told me C is right.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
12. void start() {
13. A a = new A();
14. B b = new B();
15. a.s(b);
16. b = null;
17. a = null;
18. System.out.printIn(�start completed�);
19. }
When is the B object, created in line 14, eligible for garbage collection?
A. After line 16.
B. After line 17.
C. After line 18 (when the methods ends).
D. There is no way to be absolutely certain.
E. The object is NOT eligible for garbage collection.
=======================================================
I think you can save reference of b in s().
for example:
class myStaticClass{
static B saveb;
}
class A{
void s(B b){
myStaticClass.saveb = b;
}
...
}
I hope I am right, do you think so??
Thanks.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The instance you saved will be gone, if you explicitly set b to null.

Nick
 
arden liu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
The instance you saved will be gone, if you explicitly set b to null.

Nick


Thanks anyway, But I do not agree with you.
b is one reference, but there is other reference can hold that object.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D is correct. When the method s of object a (that is of class A) is called it is passed a reference to the object that b refers to. We do not know what that method does with that reference. It could, for example, assign it to a static variable of the class A. Or it could create some Runnable object which stores the reference and start a thread which does who knows what. In any case, we do not know that zero references to the object that b refers to exist.

Yes, arden, your example would prevent the object that b refers to being eligible for garbage collection.
[ December 16, 2004: Message edited by: Barry Gaunt ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh...sorry that I overlook your example. In case you use a static variable to hold it, the instance will not go away.

The question seems to have some ambigous because it does not specify what the method a.s(b) is. However, dont worried about that, the real questions will be more clear.

Nick
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To support D Answer I was trying out some test scenario...may be this will be helpful.



Shourya
[ December 16, 2004: Message edited by: Shourya Kalinga ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"The question seems to have some ambigous because it does not specify what the method a.s(b) is".

That's the whole point of the question and exactly why choice D was given, and is the correct choice. Don't forget that SCJP 1.5 is going to be harder Nicholas
 
arden liu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
Oh...sorry that I overlook your example. In case you use a static variable to hold it, the instance will not go away.

The question seems to have some ambigous because it does not specify what the method a.s(b) is. However, dont worried about that, the real questions will be more clear.

Nick


Thanks Barry Gaunt and Nicholas Cheung.
I just try some questions from internet that are not clear. So Sometime, I was confused by the answer. I hope the real exam. could be 100% exact.
[ December 16, 2004: Message edited by: arden liu ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shourya,

Your example works because the variable xx is in fact in the same class of the XClass.

What Arden wanna point out is, if the variable xx is NOT of the same class, say, in YClass, this does not work!



Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Don't forget that SCJP 1.5 is going to be harder Nicholas


I wish the questions will not be too tricky.

By the way, Barry, will you go for SCJP Tiger?

Nick
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"By the way, Barry, will you go for SCJP Tiger?"

Most likely. But not too seriously (in the sense of the quantitivity value of my score). I'm more interested in seeing the new form of the exam and helping to ensure that the exam is quality-wise OK. And, of course, so that I can continue helping out here.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition to MCQ and DND, will there be any new question type?

Nick
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
In addition to MCQ and DND, will there be any new question type?

Nick



No idea.
 
machines help you to do more, but experience less. Experience this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic