Answer:
Following is defined the required class having accessor methods and test program:
Explanation:
class Person
{
private String doc_name;
public Person(String doc_name)
{
this.doc_name = doc_name;
}
public String getDoc_Name()
{
return doc_name;
}
}
class Doctor extends Person
{
private double office_visit_fee;
private String Specialty;
public Doctor(String doc_name,double office_visit_fee,String Specialty)
{
super(doc_name);
this.office_visit_fee = office_visit_fee;
this.Specialty = Specialty;
}
//accessor methods
public double getOffice_Visit_Fee()
{
return office_visit_fee;
}
public String getSpecialty()
{
return Specialty;
}
public String toString()
{
return "Doctor Name "+getDoc_Name()+" Office Visit Fee :$"+office_visit_fee+
" Specialty : "+Specialty;
}
}
class Test
{
public static void main (String[] args)
{
Doctor dctr = new Doctor("Joseph Lister",134.56,"Obstetrician");
System.out.println(dctr);
}
}
Output:
Doctor Name Joseph Lister Office Visit Fee :$134.56 Speciality : Obstetrician