Employee, first name, last name and ID
java
Solution
Change
public String empStat()
to
@Override
public String toString()
See how `toString()` works (and why you see Employee@523ce3f) in docs
When you use `System.out.println(nub1);` the method `nub1.toString()` is called implicitly.
Problem
I just started and it is really confusing because when I write my code there is no red warning on the eclipse, however when I run the program, it does not work. The question is: Write a program that displays employee IDs and first and last names of employees. Use two classes. The first class contains the employee data and separate methods to set the IDs and names. The other class creates objects for the employees and uses the objects to call the set methods. Create several employees and display their data. My codes are: ``` public class Employee { String lastName = null; String firstName = null; double ID; public Employee(String lastName, String firstName, double ID){ this.lastName = lastName; this.firstName = firstName; this.ID = ID; } public String empStat(){ return "Last Name: " + lastName + "First Name: " + firstName + "ID" + ID; } } ``` and ``` public class MainEmployee { public static void main(String args[]){ Employee nub1 = new Employee ("Griffin", "Peter", 000001); System.out.println(nub1); Employee nub2 = new Employee ("Griffin", "Lois", 000002); System.out.println(nub2); Employee nub3 = new Employee ("Griffin", "Stewie", 000003); System.out.println(nub3); Employee nub4 = new Employee ("Griffin", "Brian", 000004); System.out.println(nub4); } } ``` and all it does is display ``` Employee@523ce3f Employee@71b98cbb Employee@4cc68351 Employee@7cd76237 ``` can someone tell me why?