Question 3: (Inheritance)
Create an abstract class called Employee that has an abstract method call computePay() which
computes the total pay per employee using the rate per hour = $50. The method should accept
the number of hours the employee has worked. Create a child class called employeeChild and
provide the implementation. In the main method invoke that method and get the number of hours
worked from the user and pass it to the called method.
// ---------- Employee.java ---------- abstract class
public abstract class Employee {
public abstract void calculatePay(double hour);
}
import java.util.Scanner;
class EmployeeChild extends Employee{
public final double ratePerHour = 50;
@Override
public void calculatePay(double hour) {
System.out.print("Total salary per employee = " + (ratePerHour*hour) + "$");
}
}
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
EmployeeChild employeeChild = new EmployeeChild();
int hour = in.nextInt();
employeeChild.calculatePay((double) hour);
}
}
Comments
Leave a comment