230,765 views
8 votes
8 votes
Write Inheritance program for the following scenario. Employee is super class where as Manager and Regular are the sub class. Partial Employee class is created, you have to complete the Employee class and implement Manager and Regular class. The main is class is given that creates objects of all classes and displays the output.

• The subclasses uses super keyword in the constructor to assigned the data.
• All the classes implements toString() method.

Write Inheritance program for the following scenario. Employee is super class where-example-1
Write Inheritance program for the following scenario. Employee is super class where-example-1
Write Inheritance program for the following scenario. Employee is super class where-example-2
User Florian Hermann
by
2.8k points

1 Answer

14 votes
14 votes

Answer:

Step-by-step explanation:

public class Employee{

//Existing employee code

public String getName(){

return Name;

}

public double getSalary(){

return salary;

}

public int getId(){

return id;

}

public void setName(String name){

this.name = name;

}

//Manager Class

public class Manager extends Employee{

private double bonus;

public Manager(int id,String name,double salary,double bonus){

super(id,name,salary);

this.bonus = bonus;

}

public void setBonus(double bonus){

this.bonus = bonus;

}

public double getBonus(){

return bonus;

}

}

//Regular Class

public class Regular extends Employee{

private double overtime;

public Manager(int id,String name,double salary,double overtime){

super(id,name,salary);

this.overtime = overtime;

}

public void setOvertime(double overtime){

this.overtime = overtime;

}

public double getOvertime(){

return overtime;

}

}

User Le Tung Anh
by
2.5k points