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; }
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