1/3
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Define a generic class with one field, a constructor and get/set methods. Give examples of Instantiating the class with String and Integer types.
class Box<T> {
private T value;
Box(T value) { this.value = value; }
T get() { return value; }
void set(T value) { this.value = value; }
}
Box<String> nameBox = new Box<>("Alice");
String name = nameBox.get();
Box<Integer> numberBox = new Box<>(42);
Integer number = numberBox.get();Define a generic class with more than one type parameter. Define the fields, a constructor and get methods for the class. Give examples of instantiating the class with String and Integer types.
Define two generic records, one with one type parameter and one with two type parameters. Give examples of instantiating the record with String and Integer types.
Define three generic interfaces, one with one type parameter and another with two type parameters. Give an example of the interface being implemented with concrete types.