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