PujaR Agarwal

Greenhorn
+ Follow
since Mar 30, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by PujaR Agarwal

If the class definition contains a combination of instance initializer blocks in combination with the declaration of instance variables with initialization expressions, the code that comprises those items is executed in the order in which it appears in the class definition.
The code in an instance initializer block is executed after the constructor for the superclass is executed, and before the constructor for the class to which the initializer belongs is executed.





This example tests for operators understanding. Here we have to see the nature of post increment operator.

Post increment operator increments the value of variable after evaluation.

and also we have one intializer block which is called whenever a new object of class Twisty is created. This block initialize the instance variable index by 1.

so here we have dd[index++][index++]

initially we have index=1

so dd[1][index ++] and now index =2 as we are using post increment operator.

then dd[1][2] and now index=3 as we are using post increment operator.

We have,
int [][] dd = {{9,8,7}, {6,5,4}, {3,2,1,0}};

so dd[1][2] =4

so correct option is C which is 4
I downloaded examlab after april only but it is showing 19/4/09 version.


The following is from Mr. Devaka's ExamLab SCJP Simulator :
Practice Exam 1, question 42:

How many objects are eligible for the Garbage Collector, after executing the line-9 of this programm. F.Y.I: Array is an object.



According to ExamLab the answer is: 0


This problem is already discussed here but one forum is showing answer 1 and one is showing 0. which is true ? Can anyone help me.


Solution 1 :https://coderanch.com/t/418039/Programmer-Certification-SCJP/certification/about-Garbage-Collection-from-ExamLab#1843490

Solution 2 : https://coderanch.com/t/431013/Programmer-Certification-SCJP/certification/Devak-ExamLab-Garbage-Collection#1914089



Thanks
Puja
Thanks all.

This is another example of garbage collection from ExamLab

Class A{
A aob;
public static void main(String args[]){
A a=new A();
A b=new A();
A c=new C();
A.aob=b;
b.aob=a;
c.aob=a.aob;
A d=new A().aob=new(A);
c=b;
c.aob=null;
system.gc();
}
}

How many objects are eligible for garbage collection and which are they ?


I tried to solve this question and conclude that object c and d will be eligible for garbage collection. Please correct me if I am wrong.

Thanks
Puja
hello Ankit,

Can you please tell more specifically which object is eligible for garbage collection and why because by diagram I am able to understand that one object is there which is eligible for it but which one . I guessed is a2. Please clear it.


Thanks
Puja
Thanks

but I am still not sure for the correct explanation. Can anybody give the correct solution with explanation ?



Thanks Ankit,


I too made a memory map diagram for the same and I conclude that because of a2.a=null and a1=a3 just one object that is a2 is eligible for garbage collection because as a1 and a3 are still being referenced so they are not eligible . am I understanding it correctly?


Thanks
Puja

How many objects will be eligible for garbage collection after executing line 14. Please provide solution with explanation.