Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hey, my code below has error because of the word supper. there are two time i us

ID: 3843842 • Letter: H

Question

hey, my code below has error because of the word supper. there are two time i used supper in this program and both is didnt work.

package patient;

public class Female extends PatientData{
   
   
    private String nameFale;
    private int age;
    private int Age1;
    private String Address1;
    private String City1;
    private String State1;
    private String Gender1;
    private int Age;
    public Female(String fename)
    {
        super(String fename);
        this.nameFale = fename;
    }

   
    public Female(int age, String city, String address ,String state, String gender)
    {
        super(address,city,state,gender,age);
        this.Age1=age;
        this.Address1=address;
        this.City1=city;
        this.State1=state;
        this.Gender1=gender;
    }
}

Explanation / Answer

Solution :

Problem with first super :

public Female(String fename)
    {
        super(String fename);
        this.nameFale = fename;
    }

in this you want to pass fename as parameter to super class constructor.

but you have also written data type "String" over here.

When we pass something as parameter, we do not write data type.

replace it with this code :

(assuming parent class PatientData has a constructor PatientData(String s) {...} . and it takes a string as parameter.)

code :

public Female(String fename)
    {
        super(fename);
        this.nameFale = fename;
    }

This would work for sure.

--------------------------------------------------------------------------------------

Error with second super() :

super(address,city,state,gender,age);

for this one, check the syntax of constructor of parents class .

if it is like this

PatientData(String address, String city, String state, String gender, int age) {....}

then only given code "super(address,city,state,gender,age);" is correct.

if it is not the way i showed, then change it to the syntax i have written here.

another thing you can do is to change order of parameters of super() according to superclass constructor.

if constructor of class xyz is xyz(int a, String b, String c) {..} then while calling the constructor it has to be like this xyz(a,b,c) where a has to be int type, b and c has to be String type.

----------------------------------------------------------------------------------------------

Another reason for error could be both constructors of super class are not public.

check access specifier of those constructor. (Make it public if not).

If it still shows error, do type error in comment section, so that i can know where is the error.

If you have any doubts, do ask in comment section.