Sail E0 Webinar

MCQs

Total Questions : 9
Question 1.


What is the output of this program?


import java.util.*;
public class genericstack {
Stack stk = new Stack ();
public void push(E obj) {
stk.push(obj);
}
public E pop() {
E obj = stk.pop();
return obj;
}
}
class Output {
public static void main(String args[]) {
genericstack gs = new genericstack();
gs.push(36);
System.out.println(gs.pop());
}
}
  1.    H
  2.    Hello
  3.    Runtime Error
  4.    Compilation Error
 Discuss Question
Answer: Option D. -> Compilation Error

genericstack's object gs is defined to contain a string parameter but we are 

sending an integer parameter, which results in compilation error.
Output:
$ javac Output.java
$ java Output
Hello


Question 2.


What is the output of this program?


import java.util.*;
class Output {
public static void addNumbers(List
  1.    1
  2.    2
  3.    3
  4.    6
 Discuss Question
Answer: Option A. -> 1

None.
Output:
$ javac Output.java
$ java Output
1


Question 3.


What is the output of this program?


import java.util.*;
class Output {
public static double sumOfList(List
  1.    5.0
  2.    7.0
  3.    8.0
  4.    6.0
 Discuss Question
Answer: Option B. -> 7.0

None.
Output:
$ javac Output.java
$ java Output
7.0


Question 4.


What is the output of this program?


import java.util.*;
public class genericstack {
Stack stk = new Stack ();
public void push(E obj) {
stk.push(obj);
}
public E pop() {
E obj = stk.pop();
return obj;
}
}
class Output {
public static void main(String args[]) {
genericstack gs = new genericstack();
gs.push("Hello");
System.out.print(gs.pop() + " ");
genericstack gs = new genericstack();
gs.push(36);
System.out.println(gs.pop());
}
}
  1.    Error
  2.    Hello
  3.    36
  4.    Hello 36
 Discuss Question
Answer: Option D. -> Hello 36

None.
Output:
$ javac Output.java
$ java Output
Hello 36



Question 5.

Which of the following cannot be Type parameterized?


  1.    Oveloaded Methods
  2.    Generic methods
  3.    Class methods
  4.    Overriding methods
 Discuss Question
Answer: Option A. -> Oveloaded Methods

Cannot Overload a Method Where the Formal Parameter Types of Each Overload 

Question 6.

Which of these Exception handlers cannot be type parameterized?


  1.    catch
  2.    throw
  3.    throws
  4.    All of the mentioned
 Discuss Question
Answer: Option D. -> All of the mentioned

we cannot Create, Catch, or Throw Objects of Parameterized Types as generic 

class cannot extend the Throwable class directly or indirectly.


Question 7.

Which of these instance cannot be created?


  1.    Integer instance.
  2.    Generic class instance.
  3.    Generic type instance.
  4.    Collection instances.
 Discuss Question
Answer: Option C. -> Generic type instance.

It is not possible to create generic type instances. Example - "E obj = new E()"

will give a compilation error.


Question 8.

Which of these types cannot be used to initiate a generic type?


  1.    Integer class
  2.    Float class
  3.    Primitive Types
  4.    Collections
 Discuss Question
Answer: Option C. -> Primitive Types

None.


Question 9.

Which of these data type cannot be type parameterized?


  1.    Array
  2.    List
  3.    Map
  4.    Set
 Discuss Question
Answer: Option A. -> Array

None.


Latest Videos

Latest Test Papers