/* Author : Michael Robinson Program : theToStringDemoClass.java Purpose : Learning to use the toString java method This is a class that is called by the the_toStringObjectMain.java main program Updated : August 18, 2012 */ public class theToStringDemoClass { private int day; private int month; private int year; public theToStringDemoClass( int myDay, int myMonth, int myYear ) { day = myDay; month = myMonth; year = myYear; //when using the 'this' command (references the current object) it calls //it's toSring method System.out.println( "\nData received by the theToStringDemoClass " + "constructor is " + this ); }//end public theToStringDemoClass( int d, int m, int y ) /* If the toString method is not declared in the class that is using the ' 'this' command to print, java will NOT give an error but it will print the name of the class and its address */ public String toString() { //the return can be any format you need return String.format( "%d/%d/%d", day, month, year ); }//end public String toString() }//end public class theToStringDemoClass