Question
Use the Java hierarchy you posted in Week 3 (corrected based on any feedback you may have received) add one overriding method and one overloading.
Use the Java hierarchy you posted in Week 3 (corrected based on any feedback you may have received) add one overriding method and one overloading. The main method should create an instance of the class and demonstrate the correct functionality of the overriding and overloading methods.
public class Employee {
String empName;
double salary;
//constructor of UEmployee
Employee(String empName,double salary)
{
this.empName=empName;
this.salary=salary;
}
//function to return the employee name
String getName()
{
return empName;
}
//function to return the salary
double getSalary()
{
return salary;
}
public String toString()
{
String output="";
output=output+"Name: "+getName()+" ";
output=output+"Salary: $"+getSalary()+" ";
return output;
}
}
class Faculty extends Employee
{
String deptName;
//constructor of the Faculty
Faculty(String nm,double sal,String dnm)
{
//passing the name and salary to superclass constructor
super(nm,sal);
deptName=dnm;
}
//function to return department name
String getDeptName()
{
return deptName;
}
public String toString()
{
System.out.println(super.toString());
return "Departname: "+getDeptName()+" ";
}
}
class Staff extends Employee
{
String jobTitle;
//constructor of Staff class
Staff(String nm,double sal,String title)
{
//passing the name and salary to superclass constructor
super(nm,sal);
jobTitle=title;
}
//function to return job title
String getJobTitle()
{
return jobTitle;
}
public String toString()
{
System.out.println(super.toString());
return "Job Title: "+getJobTitle()+" ";
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started