If any one could explain how they got the answers Analyze the following code: pu
ID: 3546877 • Letter: I
Question
If any one could explain how they got the answers
Analyze the following code:
public class Color {
private int r; //red hue
private int g; //green hue
private int b; //blue hue
public Color( ) {
r = 0;
g = 0;
b = 0;
}
}
7. True or False: The Color constructor is an example of an overloaded constructor?
8. If I have instantiated a Color object as follows:
Color color1 = new Color();
Which would properly call an Accessor method for the red instance variable
a. color1 = getR( );
b. int rValue = color1.toR( );
c. int rValue = color1.getR();
d. int rValue = getR(color1);
Explanation / Answer
Analyze the following code:
public class Color {
private int r; //red hue
private int g; //green hue
private int b; //blue hue
public Color( ) {
r = 0;
g = 0;
b = 0;
}
}
7. True or False: The Color constructor is an example of an overloaded constructor?
False. Color constructor is example of default constructor not overloaded constructor.
8. If I have instantiated a Color object as follows:
Color color1 = new Color();
Which would properly call an Accessor method for the red instance variable
c. int rValue = color1.getR();
in Java, Accessor method should be called on top of object with name get<variable Name with first letter as capital>