File tree Expand file tree Collapse file tree
com.vogella.javastarter.exercises1/src/com/vogella/javastarter/exercises1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,8 +7,8 @@ public static void main(String[] args) {
77 // I set the age of the person to 32
88 pers .setAge (32 );
99
10- // Just for testing I write this to the console
11- System .out .println (pers . toString () );
10+ // this calls the toString method on the pers object
11+ System .out .println (pers );
1212 /*
1313 * Actually System.out.println calls always toString, if you do not
1414 * specify it so you could also have written System.out.println(pers);
Original file line number Diff line number Diff line change @@ -46,13 +46,9 @@ public void setAddress(Address address) {
4646 this .address = address ;
4747 }
4848
49- void writeName () {
50- // Writes the firstname
51- System .out .println (firstName );
52-
53-
54- // Alternatively you can combine strings with +
55- System .out .println (firstName + " " + lastName + "" + age );
49+ @ Override
50+ public String toString () {
51+ return firstName + " " + lastName ;
5652 }
5753
5854}
You can’t perform that action at this time.
0 commit comments