(Java) Question 3 Explain the answer step-by-step and include verbal explanation. Thank you! What will the following display to the console (don't run the code until you work it out by hand!) public class Person { String name; public Person(String name) { this.name = name; } public void printGreeting() { System.out.println("Hi, my name is, " + name + "!"); } } public class Student extends Person { double gpa; public Student(String name, double gpa) super(name); this.gpa = gpa; } public void printGreeting() { super.printGreeting(); System.out.println("My GPA of " + gpa + " is higher than yours!"); } } public class Test { public static void main(String[] args) { Person yan = new Person("Yan"); Person leann = new Student("Leann", 4.0); Student anh = new Student("Anh", 3.95); yan.printGreeting(); leann.printGreeting(); anh.printGreeting(); } }
(Java)
Question 3
Explain the answer step-by-step and include verbal explanation. Thank you!
What will the following display to the console (don't run the code until you work it out by hand!)
public class Person {
String name;
public Person(String name) {
this.name = name;
}
public void printGreeting() {
System.out.println("Hi, my name is, " + name + "!");
}
}
public class Student extends Person {
double gpa;
public Student(String name, double gpa)
super(name);
this.gpa = gpa;
}
public void printGreeting() {
super.printGreeting();
System.out.println("My GPA of " + gpa + " is higher than yours!");
}
}
public class Test {
public static void main(String[] args) {
Person yan = new Person("Yan");
Person leann = new Student("Leann", 4.0);
Student anh = new Student("Anh", 3.95);
yan.printGreeting();
leann.printGreeting();
anh.printGreeting();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images