197k views
4 votes
Write an overloaded constructor for the Table class that will take a single argument for the color of the table Write a set method (also known as a mutator method) for the color attribute.

1 Answer

1 vote

Step-by-step explanation:

Below is required code in java :-

public class Table{

private String color; //attribute to store the color of the table

public Table(){ //default constructor

this.color=""; //set a default blank color

}

public Table(String color){ //overloaded constructor

this.color=color; //set the color value equal to the parameter provided

}

public void setColor(String color){ //setter or mutator method

this.color=color; //set the color value equal to the parameter provided

}

}

User Rigel Chen
by
8.2k points