Java ResourceBundle .setParent (ResourceBundle parent)

Syntax

ResourceBundle.setParent(ResourceBundle parent) has the following syntax.

protected void setParent(ResourceBundle parent)

Example

In the following code shows how to use ResourceBundle.setParent(ResourceBundle parent) method.


/* w  ww  .  j  av a2  s. c  o  m*/
import java.util.Enumeration;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.StringTokenizer;

class MainResourceBundle extends ResourceBundle {

   @Override
   public Object handleGetObject(String key) {
      if (key.equals("hello")) {
         return "Hello from java2s.com!";
      } else {
         return null;
      }
   }

   @Override
   public Enumeration getKeys() {
      StringTokenizer key = new StringTokenizer("Hello from java2s.com!");
      return key;
   }

   @Override
   protected void setParent(ResourceBundle parent) {
      super.setParent(parent);
   }


}
public class Main{
  public static void main(String[] args) {

    ResourceBundle bundle =
        MainResourceBundle.getBundle("hello", Locale.US);

    System.out.println(bundle.getString("hello"));

 }
}