Ask Question

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.

+2
Answers (1)
  1. 15 November, 22:28
    0
    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;

    }

    }

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create a subclass of Person called Lecturer that has 2 variables of its own: employeeNumber and salary. As in the above scenario, these ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers