I'm trying to print out the details of a Person
which contains an int and two Strings in my main method. I know I ave to use the toString()
method but I can't remember how I would use this method to print out the details of each Person correctly. I'm assuming I must create a toString()
method in my Person
class and but I'm unsure as to what I must put into this. In my main method, I have put this:
System.out.println("Person: " + Person.Ben.toString());
System.out.println("Person: " + Person.Georgia.toString());
System.out.println("Person: " + Person.Tom.toString());
System.out.println("Person: " + Person.Beth.toString());
What would go inside of here to complete this?
public Person toString()
{
//what goes here?
}
At the moment I'm getting this output:
Person: coursework.Person$1@15db9742
Person: coursework.Person$2@6d06d69c
Person: coursework.Person$3@7852e922
Person: coursework.Person$4@4e25154f
Any help is appreciated, thanks.