I am having difficulty extending a person class to a patient class
I have a Person class with a constructor looking like
  public Person(String firstname,String surname) {
        fFirstname=firstname;
        fSurname=surname;
    }
I then have a Patient Class
public class Patient extends Person
I want to have a constructor for a patient looking roughly like
public Patient(String hospNumber) {
    fFirstname = lookup(hospNumber,"firstname");
    fSurname = lookup(hospNumber,"surname");
}
However I get a complaint that the Patient constructor needs (String,String). I can see why this is, but can't see how to extend the person class for a patient.
Just pass the result of those two method calls to the super constructor:
public Patient(String hospNumber) {
    super(lookup(hospNumber,"firstname"), lookup(hospNumber,"surname"));
}
Those methods have to be static, since the this they would otherwise been called on hasn't been constructed yet when they're invoked.
Either you can have a default constructor in Person class
public Person() {
}
Or
You need to call constructor the Person class using super method as its a 2-arg constructor
public Patient(String hospNumber) {
    super(lookup(hospNumber,"firstname"), lookup(hospNumber,"firstname"));
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With