Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 18

Given the content of /resourses/Message.properties:

welcome1="Good day!"

and given the code fragment:

Properties prop = new Properties ();

FileInputStream fis = new FileInputStream ("/resources/Message.properties"); prop.load(fis);

System.out.println(prop.getProperty("welcome1"));

System.out.println(prop.getProperty("welcome2", "Test"));//line n1

System.out.println(prop.getProperty("welcome3"));

What is the result?

    Correct Answer: C

    The program reads the properties from the 'Message.properties' file. The property 'welcome1' has the value 'Good day!', which will be printed first. The second System.out.println call uses 'welcome2' as the key with a default value of 'Test'. Since 'welcome2' is not defined in the properties file, it prints 'Test'. The third System.out.println call looks for 'welcome3', which is also not defined and thus returns null. Therefore, the printed result is 'Good day! Test null'.

Discussion
PontPontOption: C

answer is C

steefaandOption: C

Answer is C as getProperty returns null if key is not found as opposed to getString in ResourceBundle which throws MissingResourceException if key is not found.

r1muka5Option: C

Correct answer is C. Tested.

OhayouOption: C

C. but more Correct answer is : "Good day!" Test null

WilsonKKerllOption: C

C. tested