class Day { private int year, month, day; public Day(int y, int m, int d) { this.year = y; this.month = m; this.day = d; } // Return a string for the day like dd MMM yyyy public String toString() { final String[] MonthNames = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; return day + " " + MonthNames[month - 1] + " " + year; } } public class Main_testVarDay { private static void testing1() { Day d1; // System.out.println(d1); //Error: The local variable d1 may not have been // initialized // System.out.println(d1.toString()); //Error: The local variable d1 may not // have been initialized } private static void testing2() { Day d1; d1 = null; System.out.println(d1); // print: null System.out.println(d1.toString()); // Runtime exception: java.lang.NullPointerException } private static void testing3() { Day d1 = new Day(2014, 1, 15); System.out.println(d1); // something like DayX@2d4b1fda System.out.println(d1.toString()); // something like DayX@2d4b1fda } public static void main(String[] args) { // testing1(); // testing2(); testing3(); } }