Question: 6 -
Where is a new object allocated memory?
-
Old space
-
Young space
-
JVM
-
Young or Old space depending on space availability
Answer:
Young space
Solution:
A new object is always created in young space. Once young space is full, a special young collection is run where objects which have lived long enough are moved to old space and memory is freed up in young space for new objects.
A new object is always created in young space. Once young space is full, a special young collection is run where objects which have lived long enough are moved to old space and memory is freed up in young space for new objects.
Question: 7 -
Which of the following is a garbage collection technique?
-
Mark and sweep model
-
Cleanup model
-
Space management model
-
Sweep model
Answer:
Mark and sweep model
Solution:
A mark and sweep garbage collection consists of two phases, the mark phase and the sweep phase. I mark phase all the objects reachable by java threads, native handles and other root sources are marked alive and others are garbage. In sweep phase, the heap is traversed to find gaps between live objects and the gaps are marked free list used for allocating memory to new objects.
A mark and sweep garbage collection consists of two phases, the mark phase and the sweep phase. I mark phase all the objects reachable by java threads, native handles and other root sources are marked alive and others are garbage. In sweep phase, the heap is traversed to find gaps between live objects and the gaps are marked free list used for allocating memory to new objects.
Question: 8 -
When is the B object, created in line 3, eligible for garbage collection? void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println(""start completed""); /* Line 7 */
}
-
after line 7
-
There is no way to be absolutely certain.
-
after line 6
-
after line 5
Answer:
There is no way to be absolutely certain.
Solution not available.
Question: 9 -
How many objects are eligible for garbage collection after execution of line ?
public class Test
{
public static void main(String[] args)
{
m1(); // Line
}
static void m1()
{
Test t1 = new Test();
Test t2 = new Test();
}
}
-
0
-
3
-
1
-
2
Answer:
2
Solution:
Since t1 and t2 are local objects of m1() method, so they become eligible for garbage collection after complete execution of method unless any of them is returned.
Since t1 and t2 are local objects of m1() method, so they become eligible for garbage collection after complete execution of method unless any of them is returned.
Question: 10 -
Which of the following has the highest memory requirement?
-
Heap
-
Stack
-
JVM
-
Class
Answer:
JVM
Solution:
JVM is the super set which contains heap, stack, objects, pointers, etc.
JVM is the super set which contains heap, stack, objects, pointers, etc.