Question 1 of 25
Hints left: 3
Q1
Which of the following is NOT a generic type parameter in Java?
Q2
What does the term "type erasure" mean in Java generics?
Q3
Which of these is an correct way making a list that is upper bounded by class Number?
Q4
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()); } }
Q5
Which of these is wildcard symbol?
Q6
What is the primary advantage of using generics in Java?
Q7
Which of these instance cannot be created?
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 <Integer> gs = new genericstack<Integer>(); gs.push(36); System.out.println(gs.pop()); } }
Q9
What is the purpose of the `get(int index)` method in a generic list in Java?
Q10
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)"); } }
Q11
Which of these Exception handlers cannot be type parameterized?
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 are generic methods?
Q14
In Java generics, what is the purpose of the `Enum` interface?
Q15
In Java, what is the result of the expression `List list = new ArrayList<>();`?
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
What is the result of the following Java code? List super Integer> list = new ArrayList<>(); list.add(new Object());
Q18
In Java generics, what is the purpose of the `Pair` class?
Q19
Which of these keywords is used to upper bound a wildcard?
Q20
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)); } }
Q21
In Java, which generic class is commonly used for creating key-value pairs?
Q22
What does the term "bounded type parameter" mean in Java generics?
Q23
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()); } }
Q24
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()); } }
Q25
Which of these data type cannot be type parameterized?