Question: What is output: public class TestPerson { public static void main(String args) { Student myStudent = new Student(Hans, 16, 2.4); Teacher myTeacher = new Teacher(Einstein,

What is output: public class TestPerson { public static void main(String args) { Student myStudent = new Student("Hans", 16, 2.4); Teacher myTeacher = new Teacher("Einstein", 38, "Math"); myStudent.printInfo(); System.out.println(); myTeacher.printInfo(); } }public abstract class Person { protected String name; protected int age; abstract void printInfo(); public String getNameAndAge() { return this.name ", " age " years"; } }public class Student extends Person { private double gpa; public Student(String studentName, int studentAge, double studentGPA) { this.name = studentName; this.age = studentAge; this.gpa = studentGPA; } public void printInfo() { String nameAndAge = this.getNameAndAge(); System.out.println(nameAndAge); System.out.println("GPA: " this.gpa); } }public class Teacher extends Person { private String subject; public Teacher(String teacherName, int teacherAge, String teacherSubject) { this.name = teacherName; this.age = teacherAge; this.subject = teacherSubject; } public void printInfo() { String nameAndAge = this.getNameAndAge(); System.out.println(nameAndAge); System.out.println("Subject: " this.subject); } }

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 Programming Questions!