82.3k views
4 votes
Create a subclass of Person called Lecturer that has 2 variables of its own: employeeNumber and salary. As in the above scenario, these variables should be declared private with the appropriate getter and setter methods to access them.

1 Answer

3 votes

Answer:

Following are the class is given below

public class Lecturer extends Person

{

private String employeeNumber;// private variable

private double salary; // private variable

public String getempnumber() // getter method for employeeNumber

{

return employeeNumber;

}

public void setempnumber(String employeeNumber) // setter method for employeeNumber variable

{

this.employeeNumber = employeeNumber;

}

public double getempsalary() //getter method for salary variable

{

{

return salary;

}

public void setempsalary(double salary)//setter method for salary variable

{

this.salary = salary;

}

}

Step-by-step explanation:

In this program we create a subclass Lecturer which inherit person class we declared a two private member in this class one is employeeNumber which is String type because string can hold integer as well as characters and second is salary which is double type then after that we create a setter method and getter method for both the variable .

for variable “employeeNumber” we create a public void setempnumber(String employeeNumber) for setter method and public int getempnumber() for getter method similarly for variable “salary” we create public void setempsalary(double salary) setter method and public double getempsalary() for getter method.

User Padarom
by
6.8k points