Generic Classes QuizJ8 Home « Generic Classes Quiz

The questions in this quiz on Java are on the topics covered in the Generics section of the site. The table below lists the lesson used for each quiz, a description of the lesson content and the quiz number and questions associated with that lesson.

Lesson Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that quiz.

Click on a quiz in the table to go straight to the quiz for a particular lesson.

Generics Lessons Description Quiz Info.
Lesson 1 - Generic BasicsIn our first lesson on on generics we unravel the terminology behind java generics and look at some of the strange syntax we get when using it.Quiz1
7 questions
Lesson 2 - Raw/Generic Type ComparisonIn this lesson we compare raw and generic types to see the advantages of using generics.Quiz2
6 questions
Lesson 3 - Generic InterfacesIn this lesson we look at generic interfaces and how to apply them in our Java code.Quiz3
6 questions
Lesson 4 - Generic ClassesThis lesson is about generic classes.This quiz.
6 questions
Lesson 5 - Bounded TypeIn this lesson on Java generics we investigate invariance and Bounded Type.Quiz5
7 questions
Lesson 6 - Unbounded Wildcard TypeIn this lesson we learn about generic Unbounded Wildcard Type.Quiz6
6 questions
Lesson 7 - Upper Bounded Wildcard TypeThis lesson on generics is about upper bounded wildcard types.Quiz7
6 questions
Lesson 8 - Lower Bounded Wildcard TypeThis lesson on generics is about lower bounded wildcard types.Quiz8
6 questions
Lesson 9 - Generic MethodsThis lesson is about generic methods.Quiz9
6 questions
Lesson 10 - Generic ConstructorsIn our final lesson on generics we look at generic constructors.Quiz10
7 questions

Generics Quiz 4

The quiz below tests your knowledge of the material learnt in Generics - Lesson 4 - Generic Classes.

Question 1 : What's the difference between creating generalized classes using an Object reference and generics?
- Using an <code>Object</code> reference isn't type safe and generics are.
Question 2 : How would we declare a generic class that accepts any object?
public class SimpleGenericClass<> { ... } //1
public class SimpleGenericClass<Object> { ... } //2
public class SimpleGenericClass<T> { ... } /3
public class SimpleGenericClass<?> { ... } //4
- We would declare a generic class that accepts any object using answer 3.
Question 3 : Which of the following code snippets is invalid?
SimpleGenericClass genStringObj = new SimpleGenericClass<String>("A stitch in time"); //1
SimpleGenericClass genDoubleObj = new SimpleGenericClass<double>(123.456); //2
SimpleGenericClass genIntegerObj = new SimpleGenericClass<Integer>(123); //3
- Answer 3 is invalid as you can't use primitive types with generics.
Question 4 : In the following code snippet what is the T between the angled brackets known as?
public class SimpleGenericClass<T>();
- The <code>T</code> between the angled brackets is known as a <i>formal type parameter</i>.
Question 5 : Is the following code snippet valid?
private final <T> genericObj;
- The code snippet is valid as its perfectly acceptable to use generics in a declaration.
Question 6 : In a generic class we can use a T formal type parameter within a declaration, constructor or method.?
- In a generic class we CAN we can use a <code>T</code> <i>formal type parameter</i> within a declaration, constructor or method.
Quiz Progress Bar Please select an answer

What's Next?

In the next quiz we test your knowledge of Bounded Type.