Java OCA OCP Practice Question 2088

Question

Given this properties file used to load the Properties object props and this code snippet, what is the output?.

mystery=bag 
type=paper 
18:  System.out.print(props.getProperty("mystery")); 
19:  System.out.print(" "); 
20:  System.out.print(props.getProperty("more")); 
  • A. bag
  • B. bag null
  • C. bag
  • D. This code throws a runtime exception on line 20.


B.

Note

Line 18 prints the value for the property with the key mystery, which is bag.

Line 19 prints a space.

Line 20 doesn't find the key more so it prints null.

Therefore, it prints bag null, and Option B is correct.




PreviousNext

Related