Skip to content

Commit 58aa2c6

Browse files
committed
Java starter exercise reworked
1 parent c7f6efb commit 58aa2c6

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

com.vogella.javastarter.exercises1/src/com/vogella/javastarter/exercises1/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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);

com.vogella.javastarter.exercises1/src/com/vogella/javastarter/exercises1/Person.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)