I'm just learning about inheritence and am stuck on a simple problem. I want to override the print() statement in the one class with a new one in it's subclass two. I'm not sure how I would approach it as it is a void statement 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() {
// override code here to include code from class one + displaying GPA..
}
}
So for example, example.print() would print
Name: Jack
Age: 34
The desired output I want is
Name: Jack
Age: 34
GPA: 3.20
I am thinking I have to use the super method but cannot find a way to incorporate it correctly. Any tips would be appreciated!