Question 1 of 25
Hints left: 3
Q1
In Java, which generic class is commonly used for creating key-value pairs?
Q2
Which of these Exception handlers cannot be type parameterized?
Q3
What is the result of the following Java code? List super Integer> list = new ArrayList<>(); list.add(new Object());
Q4
What will be the output of the following Java program? import java.util.*; class Output { public static double sumOfList(List<? extends Number> list) { double s = 0.0; for (Number n : list) s += n.doubleValue(); return s; } public static void main(String args[]) { List<Double> ld = Arrays.asList(1.2, 2.3, 3.5); System.out.println(sumOfList(ld)); } }
Q5
What are generic methods?
Q6
Which of these keywords is used to upper bound a wildcard?
Q7
In Java generics, what is the purpose of the `Pair` class?
Q8
What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <String> gs = new genericstack<String>(); gs.push("Hello"); System.out.print(gs.pop() + " "); genericstack <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q9
Which of these instance cannot be created?
Q10
What is the primary advantage of using generics in Java?
Q11
What will be the output of the following Java code? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <String> gs = new genericstack<String>(); gs.push("Hello"); System.out.print(gs.pop() + " "); genericstack <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q12
What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q13
What will be the output of the following Java program? import java.util.*; class Output { public static void addNumbers(List<? super Integer> list) { for (int i = 1; i <= 10; i++) { list.add(i); } } public static void main(String args[]) { List<Double> ld = Arrays.asList(); addnumbers(10.4); System.out.println("getList(2)"); } }
Q14
What is the purpose of the `get(int index)` method in a generic list in Java?
Q15
In Java generics, what is the purpose of the `Enum` interface?
Q16
What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q17
Which of these data type cannot be type parameterized?
Q18
What does the term "bounded type parameter" mean in Java generics?
Q19
Which of the following is NOT a generic type parameter in Java?
Q20
Which of these is wildcard symbol?
Q21
What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <String> gs = new genericstack<String>(); gs.push("Hello"); System.out.print(gs.pop() + " "); genericstack <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q22
What will be the output of the following Java program? import java.util.*; public class genericstack <E> { Stack <E> stk = new Stack <E>(); 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 <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q23
In Java, what is the result of the expression `List list = new ArrayList<>();`?
Q24
Which of these is an correct way making a list that is upper bounded by class Number?
Q25
What does the term "type erasure" mean in Java generics?