Question: JAVA PROGRAMMING: Look at the following code and then answer the questions from Q1 to Q3 //Person.java public abstract class Person { protected String person_name;

JAVA PROGRAMMING:

Look at the following code and then answer the questions from Q1 to Q3

//Person.java

public abstract class Person {

protected String person_name;

protected int age;

private String city;

public Person() {

System.out.println("Constructor of Person class"); }

public void set_name(String name) {

person_name = name ; }

public String get_name() {

return person_name; }

public void set_age(int p_age) {

age = p_age; }

public int get_age() {

return age; }

public void my_method() {

System.out.println("I need to focus during the exam"); }

public abstract void display_information();

public abstract void do_something();}

//Employee.java

public class Employee extends Person{

private long employee_id = 531231;

public Employee() {

System.out.println("Constructor of Employee class"); }

public void set_id(long id) {

employee_id = id; }

public long get_id () {

return employee_id; }

@Override

public void display_information() {

System.out.println("Name: " + person_name);

System.out.println("Age: " + age);

System.out.println("ID: " + employee_id); }

@Override

public void do_something() {

System.out.println("I am an Employee"); }

}

//Student.java

public class Student extends Person {

private long student_id = 877552;

public Student() {

System.out.println("Constructor of Student class"); }

public void set_student_id(long id) {

student_id = id; }

public long get_student_id() {

return student_id; }

@Override

public void display_information() {

System.out.println("Name: " + person_name);

System.out.println("Age: " + age);

System.out.println("ID: " + student_id); }

@Override

public void do_something() {

System.out.println("I am a student"); }

}

Q1. What is the output of the following program?

// Program 1.java

//TestPerson

public class TestPerson {

public static void main(String[] args) {

Employee e1 = new Employee();

Student p1 = new Student(); }

}

Q2. Does the program below compile? If not, why?

// Program 2

//TestPerson.java

public class TestPerson {

public static void main(String[] args) {

Person p1 = new Person(); }

}

Q3. What is the output of the following program?

// Program 3

//TestPerson

public class TestPerson {

public static void main(String[] args) {

Employee e1 = new Employee();

e1.display_information(); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!