Java SE 8 Programmer II — Question 182

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?

Answer options

Correct answer: C

Explanation

The correct answer is C because the property 'welcome1' is found and returns 'Good day!', while 'welcome2' is not found, leading to the default value 'Test' being printed. The property 'welcome3' is also not found, which results in 'null' being printed after 'Test'. The other options are incorrect as they either misrepresent the output or suggest an exception or compilation error that does not occur.