//Topic07 Generic Programming P.11 class Pair { public Object first; public Object second; public Pair() { } public Pair(Object first, Object second) { this.first = first; this.second = second; } @Override public String toString() { return "(1)" + first + " (2)" + second; } } public class Main { public static void main(String[] args) { System.out.println("Demo Pair (Generic)\n====================="); Pair p0 = new Pair(); Pair p1 = new Pair("hello", "cheers"); Pair p5 = new Pair(123, "cheers"); System.out.println(p0); // (1)null (2)null System.out.println(p1); // (1)hello (2)cheers System.out.println(p5); // (1)123 (2)cheers System.out.println(p1.first.getClass().toString()); System.out.println(p5.first.getClass().toString()); System.out.println(p1.second.getClass().toString()); System.out.println(p5.second.getClass().toString()); } }