Why does the given code produce runtime exception w.r.t the constructor ? ----------- import java.applet.Applet; import java.awt.*; public class Sample extends Applet { private String text = "Hello World"; public void init() { add(new Label(text)); } public Sample (String string) { text = string; }
}
Surya Bahadur
Ranch Hand
Joined: Sep 28, 2000
Posts: 88
posted
0
Hi Provide a default constructor for the class or remove the constructor which takes the string,it works. Surya
Dev Prakash
Greenhorn
Joined: Oct 09, 2000
Posts: 28
posted
0
Java Applets are invoked by Browsers's JVM and they expect a public no-arg constructor. If you do not specify a constructor, compiler automatically adds one no-arg constructor BUT when you define your own constructor, compiler does not put any, hence the error. -Dev Prakash
Vikram Misra
Greenhorn
Joined: Sep 23, 2000
Posts: 2
posted
0
Applets does not have constructors instead they have init()