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?
Click on the arrows to vote for the correct answer
A. B. C. D.C.
The code fragment loads the content of the properties file "/resources/Message.properties" into a Properties object named "prop" and then prints the values of three properties using the getProperty() method:
The content of the properties file is: welcome1="Good day!"
Here is what happens when the code is executed:
prop.getProperty("welcome1"): This line retrieves the value of the property "welcome1" from the Properties object "prop". The value of "welcome1" is "Good day!". Therefore, the output of the first System.out.println() statement is "Good day!".
prop.getProperty("welcome2", "Test"): This line retrieves the value of the property "welcome2" from the Properties object "prop". However, "welcome2" is not defined in the properties file, so the method returns the default value "Test". Therefore, the output of the second System.out.println() statement is "Test".
prop.getProperty("welcome3"): This line retrieves the value of the property "welcome3" from the Properties object "prop". However, "welcome3" is not defined in the properties file, so the method returns null. Therefore, the output of the third System.out.println() statement is null.
So, the correct answer is C. The program will output "Good day! Test null" to the console. There will be no compilation error.