186k views
2 votes
Java’s class Color has a constructor that takes three integers as parameters: the red, green, and blue components of the color. A class Balloon has two fields: double radius and Color color. Write a constructor for the Balloon class that takes no parameters and sets the balloon’s radius to 10 and its color to "sky blue" (with RGB values 135, 206, and 250).

User DvdG
by
4.6k points

1 Answer

3 votes

Answer:

public Balloon(){

//Invokes the 2 argument constructor for balloon with relevant

//parameters

this(10,new Color(135,206,250));

}

Step-by-step explanation:

class Balloon{

//Private fields in the Balloon class

private double radius = 0;

private Color c = null;

// Constructor with two arguments - radius and Color

public Balloon(double radius,Color c){

this.radius = radius;

this.c = c;

}

// No argument constructor

public Balloon(){

//Invokes the 2 argument constructor for balloon with relevant

//parameters

this(10,new Color(135,206,250));

}

}

User Enthouan
by
5.4k points