So, I was busy with inheritance and polymorphism. Everything was great until I got to the tester, where I had to create an array of type employees (my superclass). Currently trying to run this program, give me this error.
Exception in thread "main" java.lang.NullPointerException
I suppose this has something to do when I declare that I have employeeArray = null ;. But leaving this, I get an error message with putting each employee in an array, he says that the array of employees should be initialized, and by default this includes employeeArray = null ;. The book I have in java doesn't really touch on these types of arrays, and I am having trouble finding the answer to my problems on the Internet. Any help anyone can offer would be greatly appreciated.
I also tried something like this
Employee [] employeeArray = new Employee[3] ;
This did not return any errors, but did not return what I was looking for. This is more like what I need, but am I having problems in super and subclasses?
public class EmployeeTest { public static void main(String[] args){ Employee [] employeeArray = null; SalariedEmployee employee1 = new SalariedEmployee("Esther", "Smith", "111-111-111", 6, 2011, 2400); CommissionedEmployee employee2 = new CommissionedEmployee("Nick", "McRae", "222-222-222", 1, 1998, 50000, 0.1); SalPlusCommEmployee employee3 = new SalPlusCommEmployee("Dan", "Mills", "333-333-333", 3, 2011, 1000, 0.05, 500 ); employeeArray[0] = employee1; employeeArray[1] = employee2; employeeArray[2] = employee3; System.out.println(employeeArray[0].getEmployeeDetails); System.out.println(employee1.toString());