1. class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); / Line 6 / } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked?





Ask Your Doubts Here

Type in
(Press Ctrl+g to toggle between English and the chosen language)

Comments

  • By: guest on 02 Jun 2017 01.26 am
    Option D is correct. Garbage collection takes place after the method has returned its reference to the object. The method returns to line 6, there is no reference to store the return value. so garbage collection takes place after line 6. Option A is wrong. Because the reference to obj1 is stored in obj2[0]. The Object obj1 still exists on the heap and can be accessed by an active thread through the reference stored in obj2[0]. Option B is wrong. Because it is only one of the references to the object obj1, the other reference is maintained in obj2[0]. Option C is wrong. The garbage collector will not be called here because a reference to the object is being maintained and returned in obj2[0].
Show Similar Question And Answers
QA->Null and void....
QA->Average height of 10 students in a class is 150 cm. A boy of height 160 cm left the class and a boy of height 148 cm is admitted. Then what is the average height of the students in the class now?....
QA->There are 50 students in a class. In a class test 22 students get 25 marks each, 18 students get 30 marks each. Each of the remaining gets 16 marks. The average mark of the whole class is :....
QA->Energy stored in a compressed string is?....
QA->he average weight of 16 boys in a class is 25 kg and that of the remaining 8 boys is 15 kg. Find the average weights of all the boys in the class.....
MCQ->class HappyGarbage01 { public static void main(String args[]) { HappyGarbage01 h = new HappyGarbage01(); h.methodA(); / Line 6 / } Object methodA() { Object obj1 = new Object(); Object [] obj2 = new Object[1]; obj2[0] = obj1; obj1 = null; return obj2[0]; } } Where will be the most chance of the garbage collector being invoked?....
MCQ->What will be the output of the program? public class ExamQuestion7 { static int j; static void methodA(int i) { boolean b; do { b = i<10 | methodB(4); / Line 9 / b = i<10 || methodB(8); / Line 10 / }while (!b); } static boolean methodB(int i) { j += i; return true; } public static void main(String[] args) { methodA(0); System.out.println( "j = " + j ); } }....
MCQ->What will be the output of the program? public class Test138 { public static void stringReplace (String text) { text = text.replace ('j' , 'c'); / Line 5 / } public static void bufferReplace (StringBuffer text) { text = text.append ("c"); / Line 9 / } public static void main (String args[]) { String textString = new String ("java"); StringBuffer textBuffer = new StringBuffer ("java"); / Line 14 / stringReplace(textString); bufferReplace(textBuffer); System.out.println (textString + textBuffer); } }....
MCQ->What will be the output of the program? public class CommandArgs { public static void main(String [] args) { String s1 = args[1]; String s2 = args[2]; String s3 = args[3]; String s4 = args[4]; System.out.print(" args[2] = " + s2); } } and the command-line invocation is > java CommandArgs 1 2 3 4

....
MCQ->class Bar { } class Test { Bar doBar() { Bar b = new Bar(); / Line 6 / return b; / Line 7 / } public static void main (String args[]) { Test t = new Test(); / Line 11 / Bar newBar = t.doBar(); / Line 12 / System.out.println("newBar"); newBar = new Bar(); / Line 14 / System.out.println("finishing"); / Line 15 / } } At what point is the Bar object, created on line 6, eligible for garbage collection?....
Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use | Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions
Question ANSWER With Solution