Answer:
Following are the solution to this question:
Step-by-step explanation:
For question 1:
public class Toy//defining a class
{ private String toyName;//defining String variable
private String toyMaker;//defining String variable
private double toyCost;//defining double variable
Toy() //defining default constructor Toy
{
}
Toy(String aToyName, String aToyMaker)// defining parameterized constructor that accepts two String parameters
{
}
Toy(String aToyName, String aToyMaker, double aToyCost)// defining parameterized constructor that accepts three parameters
{
}
}
For question 2:
public class Song//defining a class Song
{
private String title;//defining String variable
private String artist;//defining String variable
private int trackMinutes;//defining integer variable
private int trackSeconds;//defining integer variable
Song() //defining default constructor
{
title = artist = "";//use String variable that holds null value
trackMinutes = trackSeconds = 0;//use integer variable that hold a value
}
Song(String title)//use parameterized constructor that holds one parameter
{
this.title = title;// use this keyword to hold title value
artist = "";// //hold value in String variable
trackMinutes = 0;//hold value in integer variable
trackSeconds = 0;//hold value in integer variable
}
Song(String t, String a) //use parameterized constructor that holds two String parameter
{
title=t; //hold value in String variable
artist=a;//hold value in String variable
trackMinutes = trackSeconds = 0; //hold value in integer variable
}
Song(String t, String a, int min, int sec) //use parameterized constructor that takes 2 String and 2 integer parameters
{
title = t;//hold value in integer variable
artist = a;//hold value in String variable
trackMinutes = min; //hold value in integer variable
trackSeconds = sec; //hold value in integer variable
}
}
In the question 1, three constructor is declared, in which one is default and two is parameterized, that accepts two string parameter and two string and one double parameter.
In the question 2, four constructor is declared, in which one is default and three is parameterized, that accepts one, two, and four parameter.