다음과 같이 하나의 메서드 만 포함하는 인터페이스를 구현하는 수퍼 클래스 (Employee)가 어디에 있는지 질문이 있습니다.하위 클래스의 메서드 호출
public interface Payable
{
double getPaymentAmount(); // calculate payment; no implementation
}
나는 방법 실적을 포함, 각각의 직원 (예를 들어 SalariedEmployee, HourlyEmployee, CommissionEmployee)에서 상속 서브 클래스의 수를 가지고있다. 내가 지급 인터페이스를 구현 및 방법 실적을 호출하는 방법 getPaymentAmount을 선언합니다. 방법 getPaymentAmount가 다음 직원 계층 구조에서 하위 클래스에 의해 상속 될하기 위해 "급 직원을 수정할 수 있습니다하도록 요청했습니다
. getPaymentAmount은 특정 서브 클래스를 호출 할 때 객체를 사용하면 해당 하위 클래스에 대해 적절한 수익 방식을 다형성 방식으로 호출합니다. "
아무도 도와 줄 수 있습니까? 하위 클래스를 편집하지 않고 Employee 클래스 메소드 getPaymentAmount에서 관련 수익 계산 방법을 어떻게 호출합니까?
은 정말 모든 도움 감사 자바에 상대 안돼서다음과 같이 Employee 클래스의 관련 부분은 다음과 같습니다
public abstract class Employee implements Payable
{
private String firstName;
private String lastName;
private String socialSecurityNumber;
// three-argument constructor
public Employee(String first, String last, String ssn)
{
firstName = first;
lastName = last;
socialSecurityNumber = ssn;
} // end three-argument Employee constructor
//getters, settters, toString override etc have been deleted.
public double getPaymentAmount()
{
???? //This is what I need help with.
}
} // end abstract class Employee
과 서브 클래스의 1 예 복용 :
public class SalariedEmployee extends Employee
{
private double weeklySalary;
// four-argument constructor
public SalariedEmployee(String first, String last, String ssn, double salary)
{
super(first, last, ssn); // pass to Employee constructor
setWeeklySalary(salary); // validate and store salary
} // end four-argument SalariedEmployee constructor
@Override
public double earnings()
{
return getWeeklySalary();
} // end method earnings
} // end class SalariedEmployee
을
무엇을 도와 드릴까요? _specifically_? –