/* Author : Michael Robinson Program : theToStringExternalClass.java Purpose : Learning to use the toString Java method Updated : August 18, 2099 */ public class theToStringExternalClass { private int day; //this is a global private variable private int month; //this is a global private variable private int year; //this is a global private variable public theToStringExternalClass( int d, int m, int y ) { day = d; //the value of d is assigned to day month = m; //the value of m is assigned to month year = y; //the value of y is assigned to year //when using the 'this' command below (references the current //object) it calls the following toString method System.out.println( "The data received by the constructor" + " is : " + this ); }//end public theToStringExternalClass( 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 in any format you want return String.format( "%d/%d/%d", year, month, day ); }//end public String toString() }//end public class theToStringExternalClass