Question
public class Person { public String name; public String address; public String phone; public String email; public Person(String name, String address, String phone, String email)
public class Person { public String name; public String address; public String phone; public String email;
public Person(String name, String address, String phone, String email) { this.name = name; this.address = address; this.phone = phone; this.email = email; } @Override public String toString() { return this.getClass().getName() + " " + name; } }
public class Student extends Person { public final String status; public Student(String name, String address, String phone, String email, String classStatus) { super(name, address, phone, email); status = classStatus; } }
public class Employee extends Person { public String office; public double salary;
public Employee(String name, String address, String phone, String email) { super(name, address, phone, email); } } public class Faculty extends Employee { public String officeHours; public int rank;
public Faculty(String name, String address, String phone, String email) { super(name, address, phone, email); } }
public class Staff extends Employee { public String title;
public Staff(String name, String address, String phone, String email) { super(name, address, phone, email); } } public static void main(String[] args) { // create objects for classes Person person = new Person("John Doe", "123 Somewhere", "415-555-1212", "johndoe@somewhere.com"); Person student = new Student("Mary Jane", "555 School Street", "650-555-1212", "mj@abc.com", "junior"); Person employee = new Employee("Tom Jones", "777 B Street", "408-888-9999", "tj@xyz.com"); Person faculty = new Faculty("Jill Johnson", "999 Park Ave", "925-222-3333", "jj@abcxyz.com"); Person staff = new Staff("Jack I. Box", "21 Jump Street", "707-212-1112", "jib@jack.com");
System.out.println(person.toString() + " "); System.out.println(student.toString() + " "); System.out.println(employee.toString() + " "); System.out.println(faculty.toString() + " "); System.out.println(staff.toString() + " "); } } I keep getting error "non static variable this cannot be referenced from a static context" and I am out of ideas. The code is question is
public static void main(String[] args) { // create objects for classes Person person = new Person("John Doe", "123 Somewhere", "415-555-1212", "johndoe@somewhere.com"); Person student = new Student("Mary Jane", "555 School Street", "650-555-1212", "mj@abc.com", "junior"); Person employee = new Employee("Tom Jones", "777 B Street", "408-888-9999", "tj@xyz.com"); Person faculty = new Faculty("Jill Johnson", "999 Park Ave", "925-222-3333", "jj@abcxyz.com"); Person staff = new Staff("Jack I. Box", "21 Jump Street", "707-212-1112", "jib@jack.com");
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started