I am creating a simple Employee class with Production Worker as a child class using Java. I've got both class fields set to private, but I just would like to know if they need to be public or not. I know that when using private fields it keeps it private from other super classes but does it work the same for inheritance? Thank you in advance for helping out. Code below
package Employee;
public class Employee {
// declare employee class fields
private String empName;
private String empId;
private String hireDate;
// default constructor
public Employee()
{
empName = "";
empId = "";
hireDate = "";
}
// constructor with arguments passed in
public Employee(String name, String id, String date)
{
empName = name;
empId = id;
hireDate = date;
}
// set methods for employee class
public void setEmpName(String name)
{
empName = name;
}
public void setEmpID(String id)
{
empId = id;
}
public void setHireDate(String date)
{
hireDate = date;
}
// get methods for employee class
public String getName()
{
return empName;
}
public String getID()
{
return empId;
}
public String getDate()
{
return hireDate;
}
// create production worker class; child to employee class
public class ProductionWorker extends Employee
{
private int shift;
private double payRate;
// default constructor
public ProductionWorker()
{
shift = 0;
payRate = 0.00;
}
// constructor with args passed in
public ProductionWorker(int s, double p)
{
shift = s;
payRate = p;
}
// set methods for the production worker class
public void setShift(int s)
{
shift = s;
}
public void setPayRate(double p)
{
payRate = p;
}
// get methods for the production worker calss
public int getShift()
{
return shift;
}
public double getPayRate()
{
return payRate;
}
}