← Back to Question List
Java Code Walkthrough #37
Basic Generic Box Class
📄 Code
Read carefully — what does this print?1class Box<T> {2 private T value;34 public Box(T value) {5 this.value = value;6 }78 public T getValue() {9 return value;10 }11}1213public class Main {14 public static void main(String[] args) {15 Box<String> strBox = new Box<>("hello");16 Box<Integer> intBox = new Box<>(100);1718 System.out.println(strBox.getValue());19 System.out.println(intBox.getValue());20 }21}