29. Consider the following inheritance example: class Anima…
29. Consider the following inheritance example: class Animal { public void speak() { System.out.println(“Animal speaks”); }} class Dog extends Animal { @Override public void speak() { System.out.println(“Dog barks”); }} public class Test { public static void main(String[] args) { Animal a = new Dog(); a.speak(); }}What is the output? ____________
Read DetailsSuppose Person also has a no‑argument constructor that sets…
Suppose Person also has a no‑argument constructor that sets name = “Unknown”. Write a Student no‑arg constructor that:· Calls the no‑arg superclass constructor.· Sets gpa to 0.0. public class Person { private String name; public Person() { this.name = “Unknown”; } public Person(String name) { this.name = name; } public String getName() { return name; }}public class Student extends Person { private double gpa; public Student(String name, double gpa) { super(name); this.gpa = gpa; } public double getGpa() { return gpa; }}
Read Details