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

Generic Pair Class

Java code walkthrough · Question 39
easyGenerics, Classes

Code

Read carefully. What does this print?
1class Pair<K, V> {
2 private K first;
3 private V second;
4 
5 public Pair(K first, V second) {
6 this.first = first;
7 this.second = second;
8 }
9 
10 public K getFirst() { return first; }
11 public V getSecond() { return second; }
12}
13 
14public class Main {
15 public static void main(String[] args) {
16 Pair<String, Integer> p = new Pair<>("age", 25);
17 System.out.println(p.getFirst());
18 System.out.println(p.getSecond());
19 }
20}

Your answer