Sail E0 Webinar

MCQs

Total Questions : 97 | Page 9 of 10 pages
Question 81.

Which of these methods can randomize all elements in a list?


  1.    rand()
  2.    randomize()
  3.    shuffle()
  4.    ambigous()
 Discuss Question
Answer: Option C. -> shuffle()

shuffle - randomizes all the elements in a list.


Question 82.

Which of these keywords is used to make a class?


  1.    class
  2.    struct
  3.    int
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> class

None.


Question 83.
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?


  1.    After line 9
  2.    After line 10
  3.    After line 11
  4.    Garbage collector never invoked in methodA()
 Discuss Question
Answer: Option D. -> Garbage collector never invoked in methodA()

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].


Question 84.

Which of these method of Object class can clone an object?


  1.    Objectcopy()
  2.    copy()
  3.    Object clone()
  4.    clone()
 Discuss Question
Answer: Option C. -> Object clone()

None.


Question 85.

Which keyword is used by method to refer to the object that invoked it?


  1.    import
  2.    catch
  3.    abstract
  4.    this
 Discuss Question
Answer: Option D. -> this

this keyword can be used inside any method to refer to the current object. this is always a 

reference to the object on which the method was invoked.


Question 86.

Which of these interface handle sequences?


  1.    Set
  2.    List
  3.    Comparator
  4.    Collection
 Discuss Question
Answer: Option B. -> List

None.


Question 87.

Which of these methods sets every element of a List to a specified object?


  1.    set()
  2.    fill()
  3.    Complete()
  4.    add()
 Discuss Question
Answer: Option B. -> fill()

 None.


Question 88.

Which class does not override the equals() and hashCode() methods, inheriting them directly 

from class Object?


  1.    java.lang.String
  2.    java.lang.Double
  3.    java.lang.StringBuffer
  4.    java.lang.Character
 Discuss Question
Answer: Option C. -> java.lang.StringBuffer

java.lang.StringBuffer is the only class in the list that uses the default methods provided by 

class Object.

Question 89.

Which of these interface declares core method that all collections will have?


  1.    set
  2.    EventListner
  3.    Comparator
  4.    Collection
 Discuss Question
Answer: Option D. -> Collection

Collection interfaces defines core methods that all the collections like set, 

Question 90.

Which of these classes is not part of Java's collection framework?


  1.    Maps
  2.    Array
  3.    Stack
  4.    Queue
 Discuss Question
Answer: Option D. -> Queue

Queue is not a part of collection framework.

Latest Videos

Latest Test Papers