Determine the output of this program:.
class Color { int red, green, blue; Color() {//from w w w . ja va 2 s. c om Color(10, 10, 10); } Color(int r, int g, int b) { red = r; green = g; blue = b; } void printColor() { System.out.println("red: " + red + " green: " + green + " blue: " + blue); } public static void main(String [] args) { Color color = new Color(); color.printColor(); } }
A
The compiler looks for the method Color()
when it reaches this statement: Color(10, 10, 10);.
The right way to call another constructor is to use the this keyword as follows: this(10, 10, 10);.