GoConqr has a new look! Let us know what you think.

Quiz

06-Objectives-Wise-Garbage-Collection

Wong Fei Hung 5 questions

Take the quiz

This quiz has a time limit, so it opens in the usual player.

Questions in this quiz (5)

  1. 1Consider the following code snippet:
    public class Test{
    void test( ) {
    MyClass obj = new MyClass( ) ;
    obj . name = " j ack" ;
    // 1 insert code here
    }
    }/
    /In MyClass. j ava
    public class MyClass{
    int value;
    String name;
    }Wha
    t can be inserted at // 1, which will make the object referred to by obj eligible for
    garbage collection?
    1. Aobj . destroy( ) ;
    2. BRuntime. getRuntime( ) . gc( ) ;
    3. Cobj = null;
    4. Dobj . finalize( )
    5. Eobj . name = null; as well as obj = null;
  2. 2Which is the earliest line in the following code after which the object created on line
    // 1 can be garbage collected, assuming no compiler optimizations are done?
    public class NewClass{
    private Obj ect o;
    void doSomething( Obj ect s) { o = s; }
    public static void main( String args[ ] ) {
    Obj ect obj = new Obj ect( ) ; // 1
    NewClass tc = new NewClass( ) ; //2
    tc. doSomething( obj ) ; //3
    obj = new Obj ect( ) ; //4
    obj = null; //5
    tc. doSomething( obj ) ; //6
    }
    }
    1. ALine 1
    2. BLine 2
    3. CLine 3
    4. DLine 4
    5. ELine 5
    6. FLine 6
  3. 3Consider the following code:
    class MyClass { }
    public class TestClass{
    MyClass getMyClassObj ect( ) {
    MyClass mc = new MyClass( ) ; //1
    return mc; //2
    }p
    ublic static void main( String[ ] args) {
    TestClass tc = new TestClass( ) ; //3
    MyClass x = tc. getMyClassObj ect( ) ; //4
    System. out. println( " got myclass obj ect" ) ; //5
    x = new MyClass( ) ; //6
    System. out. println( " done" ) ; //7
    }
    }A
    fter what line the MyClass object created at line 1 will be eligible for garbage
    collection?
    1. A2
    2. B5
    3. C6
    4. D7
    5. ENever till the program ends.
  4. 4In the following code, after which statement (earliest), the object originally held in s,
    may be garbage collected ?
    1. public class TestClass{
    2. public static void main ( String args[ ] ) {
    3. Student s = new Student( " Vaishali" , " 930012" ) ;
    4. s. grade( ) ;
    5. System. out. println( s. getName( ) ) ;
    6. s = null;
    7. s = new Student( " Vaishali" , " 930012" ) ;
    8. s. grade( ) ;
    9. System. out. println( s. getName( ) ) ;
    10 s = null;
    }
    }
    public class Student{
    private String name, rollNumber;
    public Student( String name, String rollNumber) {
    this. name = name;
    this. rollNumber = rollNumber;
    }/
    /valid setter and getter for name and rollNumber follow
    public void grade( ) {
    }
    }
    1. AIt will not be Garbage Collected till the end ofthe program.
    2. BLine 5
    3. CLine 6
    4. DLine 7
    5. ELine 10
  5. 5Given the following code:
    class M { }
    class N{
    private M m = new M( ) ;
    public void makeItNull( M pM) {
    pM = null;
    }p
    ublic void makeThisNull( ) {
    makeItNull( m) ;
    }p
    ublic static void main( String[ ] args) {
    N n = new N( ) ;
    n. makeThisNull( ) ;
    }
    }Whi
    ch ofthe following statements are correct?
    1. AThere are no instances ofM to be garbage collected till the program ends.
    2. BA call to n. makeThisNull( ) marks the private instance ofM for garbage
      collection.
    3. CSetting pM = null; in makeItNull( ) , marks the private instance ofM for garbage
      collection.
    4. Dprivate members ofa class become eligible for garbage collection only when the
      instance ofthe class itselfbecomes eligible for garbage collection.

Information

Description
OCA-SE-7 Objective-Wise-Ethuware-OCA-SE-7 Quiz on 06-Objectives-Wise-Garbage-Collection, created by Wong Fei Hung on 01/08/2017.
Language
Português
Views
1
Rating
No ratings yet
Rate this quiz
Rate this quiz

Feedback

What is it about?

What do you think of the new look?

How do you like it?