You need to define a toString()
method for your Employee
class. By defining a custom method, you can make the String representation of your object look however you like. Otherwise, The default Object#toString()
implementation gets called, which looks basically like "ClassName@memoryaddress", as you've discovered.
For instance (extrapolating from your println
above), if you want Employee#toString()
to return the employee's information as first name, last name, and salary, separated by tabs, you could do this:
public class Employee {
// Class members and other stuff as you have them already go here...
@Override
public String toString() {
// Override the default toString() method and return a custom String instead.
return String.format("%s\t%s\t%s", first, last, money);
}
}