What is the result of compiling and running this applet: A. Prints "Hello World". B. Generates a runtime error. C. Does nothing. D. Generates a compile time error. Select the most appropriate answer. The correct answer is B I have couple of questions regarding this question. 1. Can we have a constructor in a applet. 2. I don't understand what made the run time error to be generated. Can anyone please help me with this. Thx. I added UBB Code to make this more readable. Bill [This message has been edited by bill bozeman (edited November 22, 2000).]
Hi ... It causes a Runtime Error 'Class cannot be instantiated' because the JVM is looking for the default no-arg constructor. If you add this in and recompile it works fine. Hope that helps. ------------------ Jane The cure for boredom is curiosity. There is no cure for curiosity. -- Dorothy Parker
Jane your so smart ;^) anytime you declare a constructor the JVM cannot automatically create a default one the way it does when you dont declare any. I dont see how you can actually use a constructor in an applet as there is no way i know of to pass the arguments to the constructor.
Hi Randall, I think you're right ... maybe someone out there knows how but I've been unable to figure it out. Think a ctor in an applet is redundant since, if you've written an applet, it will be loaded in an HTML page and you can use PARAM to pass any initializing variables. One thing I did discover in my attempts at using a ctor ... I tried to create a new instance of the class and then assign it to this ... got a 'cannot assign a value to final variable this' error! ------------------ Jane The cure for boredom is curiosity. There is no cure for curiosity. -- Dorothy Parker