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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!