Develop a java application using Inheritance as per the following. Create a class
Worker and derive two classes DailyWorker and SalariedWorker from it. Every
worker has name, salary rate. Provide a method ComPay(int hours) to compute the
week pay of every worker. A DailyWorker is paid on the basis of number of days
he/she works. The SalariedWorker gets paid the wage for 40 hours a week no
matter what actual hours is. Implement this scenario to calculate the pay of workers.
You are expected to use the concept of Inheritance with proper run time
polymorphism
public class Main
{
public static void main(String[] args) {
DailyWorker d=new DailyWorker();
d.ComPay(6);
SalariedWorker s=new SalariedWorker();
s.ComPay(40);
}
}
class Worker{
protected String name;
protected double salary_rate=1250;
public void ComPay(int hours){
System.out.println("Pay= "+(hours*salary_rate));
}
}
class DailyWorker extends Worker{
private int day;
public void ComPay(int days){
System.out.println("Pay= "+(days*salary_rate));
}
}
class SalariedWorker extends Worker{
public void ComPay(int hours){
System.out.println("Pay= "+(40*salary_rate));
}
}
Comments
Leave a comment