Explore BrainMass

Explore BrainMass

    java: toString Methods

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Make a class Employee with a name and salary.
    Make a class Manager inherit from Employee.
    Add an instance variable, named department, of type String. Supply a method toString that prints the manager's name, department, and salary. Make a class Executive inherit from Manager.
    Supply appropriate toString methods for all classes.
    Supply a test program that tests these classes and methods.

    © BrainMass Inc. brainmass.com June 4, 2020, 3:48 am ad1c9bdddf

    Solution Preview

    // Make a class Employee with a name and salary.
    public class Employee {
    public int salary;
    public String name;

    public String toString() {
    return (this.name + " " + this.salary);

    Employee Information
    // Class to test the Employee, Executive, and Manger Class.
    public class EmployeeInfo {
    public static void main(String[] args)

    Solution Summary

    The solution contains all the 3 base classes and the other main class that utilizes the Manager, employee and executive classes. The code is properly commented to make it easier to understand.