Suppose I have a class name Employee
class Employee
{
int empID;
String name;
public Employee(int empID,String name)
{
this.empID = empID;
this.name = name;
}
// getters and setters
}
Now I create subclass based on their position
class Manager extends Employee
{
private String salary;
private int deptID;
public Manager(String salary, int deptID,int id, String name)
{
super(id,name);
this.salary = salary;
this.deptID = deptID;
}
// getters and setters
}
If I want to access the empID and name of Manager from Manager class, how can I do that as those fields are private? I was thinking in the getter function in Manager class ,I would do super.getName() and super.getID()?
If there is anything wrong in class design pattern, please let me know. I want to make it as perfect as it can be. Thanks for help.
Aucun commentaire:
Enregistrer un commentaire