Hello,
Oracle Certified Associate
Java SE 8 Programmer 1 STUDY GUIDE EXAM 1Z0-808 Assessment
Test 1 Question 2 states:
What is the output of the following program?
1: public class WaterBottle {
2: private
String brand;
3: private boolean empty;
4: public static void main(String[] args) {
5: WaterBottle wb = new WaterBottle();
6: System.out.print("Empty = " + wb.empty);
7: System.out.print(", Brand = " + wb.brand);
8: } }
A. Line 6 generates a compiler error.
B. Line 7 generates a compiler error.
C. There is no output.
D. Empty = false, Brand = null
E. Empty = false, Brand =
F. Empty = null, Brand = null
The Study guide answer states:
D. Boolean fields initialize to false and references initialize to null, so empty is false and brand is null. Brand = null is output.
Actually answers A and B look right, because you cannot call private fields outside the class. Am I right?