Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

Evaluate x - t s/n for x = 25, t = 2, s = 8, and n = 4.

Answered: 1 week ago

Question

Draw a labelled diagram of the Dicot stem.

Answered: 1 week ago