Sail E0 Webinar

MCQs

Total Questions : 97 | Page 7 of 10 pages
Question 61.

Which of these keywords cannot be used for a class which has been declared final?


  1.    abstract
  2.    extends
  3.    abstract and extends
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> abstract

A abstract class is incomplete by itself and relies upon its subclasses to provide complete 

implementation. If we declare a class final then no class can inherit that class, an abstract 

class needs its subclasses hence both final and abstract cannot be used for a same class.


Question 62.

Which interface does java.util.Hashtable implement?


  1.    Java.util.Map
  2.    Java.util.List
  3.    Java.util.HashTable
  4.    Java.util.Collection
 Discuss Question
Answer: Option A. -> Java.util.Map

Hash table based implementation of the Map interface.


Question 63.

Which of these is Basic interface that all other interface inherits?


  1.    Set
  2.    Array
  3.    List
  4.    Collection
 Discuss Question
Answer: Option D. -> Collection

Collection interface is inherited by all other interfaces like Set, Array, Map etc. It 

defines core methods that all the collections like set, map, arrays etc will have


Question 64.

Which of these is true about unmodifiableCollection() method?


  1.    unmodifiableCollection() returns a collection that cannot be modified.
  2.    unmodifiableCollection() method is available only for List and Set.
  3.    unmodifiableCollection() is defined in Collection class.
  4.    None of the mentioned.
 Discuss Question
Answer: Option B. -> unmodifiableCollection() method is available only for List and Set.

unmodifiableCollection() is available for al collections, Set, Map, List etc.


Question 65.

Which function is used to perform some action when the object is to be destroyed?


  1.    finalize()
  2.    delete()
  3.    main()
  4.    None of the mentioned
 Discuss Question
Answer: Option A. -> finalize()

None.


Question 66.

Which of these methods deletes all the elements from invoking collection?


  1.    clear()
  2.    reset()
  3.    delete()
  4.    refresh()
 Discuss Question
Answer: Option A. -> clear()

clear() method removes all the elements from invoking collection.


Question 67.

Which operator is used by Java run time implementations to free the memory of an object 

when it is no longer needed?


  1.    delete
  2.    free
  3.    new
  4.    None of the mentioned
 Discuss Question
Answer: Option D. -> None of the mentioned

Java handles deallocation of memory automatically, we do not need to explicitly delete an element. 

Garbage collection only occurs during execution of the program. When no references to the object 

exist, that object is assumed to be no longer needed, and the memory occupied by the object can 

be reclaimed.


Question 68.

Which of these keywords can be used to prevent inheritance of a class?


  1.    super
  2.    constant
  3.    Class
  4.    final
 Discuss Question
Answer: Option D. -> final

Declaring a class final implicitly declares all of its methods final, and makes the class inheritable.


Question 69.

Which of these operators is used to allocate memory for an object?


  1.    malloc
  2.    alloc
  3.    new
  4.    give
 Discuss Question
Answer: Option C. -> new

Operator new dynamically allocates memory for an object and returns a reference to it. 

This reference is address in memory of the object allocated by new.


Question 70.
class Test
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}


When is the Demo object eligible for garbage collection?


  1.    After line 7
  2.    After line 8
  3.    After the start() method completes
  4.    When the instance running this code is made eligible for garbage collection.
 Discuss Question
Answer: Option D. -> When the instance running this code is made eligible for garbage collection.

Option D is correct. By a process of elimination.

Option A is wrong. The variable d is a member of the Test class and is never directly set to null.

Option B is wrong. A copy of the variable d is set to null and not the actual variable d.

Option C is wrong. The variable d exists outside the start() method (it is a class member). So, when the start() method finishes the variable d still holds a reference.


Latest Videos

Latest Test Papers