In this main method:
package practice;
public class PersonTest {
public static void main(String[] args)
{
Person[] people = new Person[2];
people[0] = new Person();
people[1] = new Employee();
System.out.println(people[1].job);
}
}
I get a compiler error when I try to use job. Can anyone tell me why, and how it's supposed to be done? Below are the classes I created for the above method:
The Person class:
package practice;
public class Person{
String name;
int age;
public Person () {
this.name = "undefined";
this.age = 0;
}
}
And the Employee class:
package practice;
public class Employee extends Person{
String job;
Employee () {
super();
this.job = "job";
}
}