X440: Null Pointer Exception Practice 4

For the question below, assume the following implementation of an Employee class:

class Employee {
    String name;
    public Employee(String name) {
      this.name = name;
    }
    public void setName(String name) {
      this.name = name;
    }
}

The code below is throwing a Null Pointer Exception. The code should create an array of 5 Employees and set the one at index 0 to be named "Mark". Figure out what is going wrong in this code and fix it. Think about how you would explain it if someone came to you with this problem.

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.