// every Java class implicitly inherits from Object // common methods: toString(), equals(..), hashCode(), ... public class Pair { private E v1, v2; // * Java provides a default constructor, if there is NO constructor public Pair() { } public Pair(E v1, E v2) { this.v1 = v1; this.v2 = v2; } @Override // format: Pair@xyzxyz [ 'E', 'T' ] public String toString() { //return super.toString() + " [ " + v1 + ", " + v2 + " ]"; // string concatenation return String.format("%s [ %s, %s ]", super.toString(), v1, v2); } public static void main(String[] args) { Pair p1 = new Pair<>(); Pair p2 = new Pair<>('E', 'T'); // auto boxing Pair p3 = p2; // p3 is an alias (nick-name) of p2 System.out.println(p1.toString()); System.out.println(p2.toString()); System.out.println(p3.toString()); } }