/* Author : Michael Robinson Program : the_toStringObjectMain.java Purpose : Here we learn to use the Java toString method toString is very easy to implement and very useful This is the main program where we create objects and pass data so that those objects can process and return the formatted data using their toString method. We also show what happens when we use the objects' default toString method. Updated : August 18, 2099 */ public class the_toStringObjectMain { public static void main(String arg[]) { //We created a class called theToStringDemoClass //in it we have a method called toString() to be used by this //program in several ways: //first creating an object of class the­ToStringDemoClass //this object will process and return passed data using the toString method theToStringDemoClass toStringObj = new theToStringDemoClass( 8, 18, 2099 ); //or System.out.println( "\ntheToStringDemoClass toString method " + toStringObj ); //or System.out.println( "\ntheToStringDemoClass.toString() method " + toStringObj.toString() ); System.out.println( "\n------------------------------------------------------\n" ); //This is a different way of create an object and pass data System.out.println( "\nThis is a different way of create an object and pass data"); theToStringDemoClass myInfo = new theToStringDemoClass( 8, 18, 2099 ); System.out.println( "\nThis is myInfo class " + myInfo ); System.out.println( "\n------------------------------------------------------" ); //********************************************************************** //Using a class that does NOT have a build in toString method System.out.println( "\nClass that does NOT have a build in toString method"); noToStringMethodDemo noToStringObj = new noToStringMethodDemo( 8, 18, 2099 ); //or //this object calls its toString method automatically System.out.println( "\nObject's toString method automatically " + noToStringObj ); //or //this object call its toString method manually System.out.println( "\nObject's toString method callingt it " + noToStringObj.toString() ); //this object calls it NoToString method manually System.out.println( "\nObject's NoToString toString method " + noToStringObj.NoToString() ); System.out.println( "\n------------------------------------------------------\n" ); }//end public static void main(String arg[]) }//end public class the_toStringObjectMain