CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Generic Wrapper Describe Method

Java code walkthrough · Question 45
mediumGenerics, Classes

Code

Read carefully. What does this print?
1class Wrapper<T> {
2 private T data;
3 
4 public Wrapper(T data) {
5 this.data = data;
6 }
7 
8 public String describe() {
9 return "Holds: " + data;
10 }
11}
12 
13public class Main {
14 public static void main(String[] args) {
15 Wrapper<Integer> w1 = new Wrapper<>(99);
16 Wrapper<Boolean> w2 = new Wrapper<>(true);
17 
18 System.out.println(w1.describe());
19 System.out.println(w2.describe());
20 }
21}

Your answer