I just find out about inheritance and am stuck in a simple problem. I want to redefine the print () operator in class one with a new subclass of two in it. I am not sure how I will access it, since it is a void operator with no parameters.
public class One { private String name; private int age; public human(String n, int a) name = n; age = a; } public void print() { System.out.println("Name: " + name); System.out.println("Age: " + age); }
Second class:
public class Two extends One { private double gpa; public two(String n, int a, double g) { super(n,a); gpa = g; public double getGPA (){ return gpa; } public void print() {
So, for example, example.print () will print
Name: Jack Age: 34
The desired result that I want is
Name: Jack Age: 34 GPA: 3.20
I think I need to use a super method, but I can’t find a way to enable it correctly. Any advice would be appreciated!
source share