Java OCA OCP Practice Question 1354

Question

What is the output of the following program?

1: public class Main { 
2: private String brand; 
3: private boolean empty; 
4: public static void main(String[] args) { 
5:   Main wb = new Main(); 
6:   System.out.print("Empty = " + wb.empty); 
7:   System.out.print(", Brand = " + wb.brand); 
8:  } 
9: }  
  • 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


D.

Note

Boolean fields initialize to false and references initialize to null, so empty is false and brand is null. Brand = null is output.




PreviousNext

Related