Hello,
Oracle Certified Associate
Java SE 8 Programmer 1 STUDY GUIDE EXAM 1Z0-808 Introduction Assessment
Test Question 12 states:
1: public class Egret {
2: private
String color;
3: public Egret() {
4: this("white");
5: }
6: public Egret(String color) {
7: color = color;
8: }
9: public static void main(String[] args) {
10: Egret e = new Egret();
11: System.out.println("Color:" + e.color);
12: }
13:}
A. Color:
B. Color:null
C. Color:White
D. Compiler error on line 4.
E. Compiler error on line 10.
F. Compiler error on line 11.
The Study guide answer states:
B. Line 10 calls the constructor on lines 3–5. That constructor calls the other construc- tor. However, the constructor on lines 6–8 assigns the method parameter to itself, which leaves the color instance variable on line 2 set to its default value of null. For more information, see Chapter 4.
But the right answer seems to be F, because it is prohibited to call a private field outside the class. Am I right?