Subj : Using extends command flag but cannot access inherited fields or methods To : netscape.public.mozilla.jseng From : vwine@yahoo.com (Vaughn) Date : Tue Apr 22 2003 07:08 pm Hello, I'm using the following to compile a script, named TestScript.js: java -cp ".;js.jar" org.mozilla.javascript.tools.jsc.Main -g -nosource -extends Son TestScript.js As you can see, this script extends a class named Son (which extends Daddy). I would like to be able to access member data from Son and Daddy within TestScript, but when I try I always get exceptions (see the attached source below for details). Is there something I can do to get at inherited fields and methods from my script? Thank you so much for your help! Vaughn _________________________ Here are my sources: --Daddy.java--------------------------------- public class Daddy { public int age = 34; public String getEyeColor() { return "blue"; } } --Son.java--------------------------------- public class Son extends Daddy { public String favoriteToy = "Buzz Light Year action figure"; public Son() { age = 5; } public Integer getNumToys() { return new Integer(237); } } --TestScript.js------------------------ java.lang.System.out.println("Start TestScript"); // The next four lines are bad and cause exception like the following: // // Exception in thread "main" ReferenceError: // "getEyeColor" is not defined. (TestScript.js; line 4) // at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:597) // at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:557) // at org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:254) // at TestScript1.call(TestScript.js:4) // at TestScript1.exec(TestScript.js) // at org.mozilla.javascript.ScriptRuntime.runScript(ScriptRuntime.java:1887) // at TestScript.() // at Driver.main(Driver.java:5) // // My script extends Son, so these SHOULD work! java.lang.System.out.println("My eye color = " + getEyeColor()); java.lang.System.out.println("My age = " +age); java.lang.System.out.println("My number of toys = " + getNumToys()); java.lang.System.out.println("My favorite toy = " + favoriteToy); java.lang.System.out.println("End TestScript"); --Driver.java-------------------------------- public class Driver { public static void main(String[] args) { TestScript ts = new TestScript(); // This works if I comment out the "BAD" lines in the script System.out.println("Eye color = " + ts.getEyeColor()); System.out.println("Age = " +ts.age); System.out.println("Number of toys = " + ts.getNumToys()); System.out.println("Favorite toy = " + ts.favoriteToy); } } .