• 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

ExamLab question???

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

After Line 12 , how many objects are eligible for garbage collection?
The answer is one object.

It is better to explain with the diagram and its really very helpful to me . Actually they told that we have to draw a small picture everytime whenever we see this type questions in the real exam too..

 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Actually they told that we have to draw a small picture everytime whenever we see this type questions in the real exam too


Who they?? You are not obliged to draw a diagram for these type of questions. If you can figure out the answer without any diagram, then you don't need to draw a diagram. If I have to create a diagram for this question, it would be like this
 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Ankit, I couldn't understand the program even with this diafram. If you have time, could you explain this program from line 9 (A a1 =null;) to end?



 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets see this one line at a time

9. A a1=null;    A reference of class A is created an initialized to null.
10. A a2=new A(new A(null));   Here a2 points to an Object of class A. The class A has a field named a and the instance of class A which we pass to the constructor will be set to the field a. We can split this line to understand it better

11. A a3=new A(a2);    This one is also not that tough. a3 points to an instance of A and a3.a points to a2.

The rest of the statements should be easy to understand I think...
 
jayalakshmi charugundla
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so because of a2.a=null , one class obejct is eligible for gc. And the other object is referanced by a1 and a3. Am I right?

Why you have given two boxes for one object ? You could have given only one that is enough. thats why i didn't understand.

what actually the second box says? tell me by words
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so because of a2.a=null , one class obejct is eligible for gc. And the other object is referanced by a1 and a3. Am I right?


Yes that's right.

Why you have given two boxes for one object ?


Which two boxes??
 
reply
    Bookmark Topic Watch Topic
  • New Topic