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

/resourses/Message.properties:

Given the content of -

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 given Properties file contains only one key-value pair: 'welcome1' with the value 'Good day!'. The code fragment loads this properties file and retrieves its values using the getProperty method. The first print statement outputs the value of 'welcome1', which is 'Good day!'. The second print statement attempts to retrieve the value for 'welcome2', which does not exist in the properties file. Therefore, it returns the default value 'Test'. The third print statement attempts to retrieve 'welcome3', which also does not exist in the properties file and does not have a default value, resulting in a null output. Thus, the program outputs 'Good day!', 'Test', and 'null' in that order.

Discussion
Ritesh_Option: C

It should print . "Good day!" Test null

WilsonKKerll

Correct.

InnovationOption: C

Test is given as a defaut value for welcome2 so the output is "Good day!" Test null

adnano1234Option: C

C is correct

iSnoverOption: C

The answer is A, Test is given as a defaut value for welcome2 so the output is: "Good day!" Test null