What is the result?

Given the Greetings.properties file, containing:

HELLO_MSG = Hello, everyone!

GOODBYE_MSG = Goodbye everyone!

And given:

import java.util.Enumeration;

import java.util.Locale;

import java.util.ResourceBundle;

public class ResourceApp {

public void loadResourceBundle() {

ResourceBundle resource = ResourceBundle.getBundle(“Greetings”, Locale.US);

System.out.println(resource.getObject(1));

}

public static void main(String[] args) {

new ResourcesApp().loadResourceBundle();

}

}

What is the result?

Given the Greetings.properties file, containing:

HELLO_MSG = Hello, everyone!

GOODBYE_MSG = Goodbye everyone!

And given:

import java.util.Enumeration;

import java.util.Locale;

import java.util.ResourceBundle;

public class ResourceApp {

public void loadResourceBundle() {

ResourceBundle resource = ResourceBundle.getBundle(“Greetings”, Locale.US);

System.out.println(resource.getObject(1));

}

public static void main(String[] args) {

new ResourcesApp().loadResourceBundle();

}

}

What is the result?

A.
Compilation fails

B.
HELLO_MSG

C.
GOODGYE_NSG

D.
Hello, everyone!

E.
Goodbye everyone!

Explanation:
The code will not compile.
The problem is the following line:
System.out.println(resource.getObject(1));

In particular getObject(1) throws the following error:
Exception in thread “main” java.lang.RuntimeException: Uncompilable source code – Erroneous sym type: <any>.loadResourceBundle

Note:getObject(String key)
Gets an object for the given key from this resource bundle or one of its parents.



Leave a Reply 2

Your email address will not be published. Required fields are marked *


ses

ses

so it would be right!
———————-
public void loadResourceBundle() {
ResourceBundle resource = ResourceBundle.getBundle(“ocp2.Greetings”, Locale.US);
System.out.println(resource.getObject(“hello”));

}