Question 1 of 25
Hints left: 3
Q1
What is the main purpose of generics in Java?
Q2
What is the benefit of using generics with collections in Java?
Q3
What one of the following is best practice to handle Null Pointer exception? i) int noOfStudents = line.listStudents().count; ii) int noOfStudents = getCountOfStudents(line); public int getCountOfStudents(List line) { if(line != null) { if(line.listOfStudents() != null) { return line.listOfStudents().size(); } } throw new NullPointerException("List is empty"); }
Q4
What does the `E` represent in generic class declarations in Java?
Q5
Which of the following is a valid use of generics in Java?
Q6
What is the result of the following Java code? List extends Number> list = new ArrayList<>(); list.add(new Integer(10));
Q7
What is the purpose of the `>` wildcard in a method parameter in Java generics?
Q8
Which of the following is a best practice to measure time taken by a process for execution?
Q9
Which of the below is true about java class structure?
Q10
In Java generics, what is the purpose of the `? extends T` wildcard?
Q11
Which symbol is used to denote a generic type parameter in Java?
Q12
In Java, which exception is thrown when there is a type mismatch due to generics?
Q13
What is the purpose of the `extends` keyword in Java generics?
Q14
In Java generics, what is the purpose of the `` syntax?
Q15
What does the term "type parameter" mean in Java generics?
Q16
Which of the following is a generic class in Java?
Q17
What is the result of the following Java code? List> list = new ArrayList<>(); list.add("Hello");
Q18
In a generic class, what does the wildcard `>` represent?
Q19
Which keyword is used to define generic methods in Java?
Q20
What is the purpose of the `? super T` wildcard in Java generics?
Q21
In Java generics, what is the purpose of the diamond operator (`<>`)?
Q22
Which of the below is false about java coding?
Q23
In Java generics, what is the purpose of the `? super T` wildcard?
Q24
Which is better in terms of performance for iterating an array?
Q25
What is type erasure in Java generics?