File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JDCert Q - Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JDCert Q - Applet" Watch "JDCert Q - Applet" New topic

JDCert Q - Applet

vidhya Ramachandran

Joined: Sep 15, 2000
Posts: 13
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
Provide a default constructor for the class or remove the constructor which takes the string,it works.
Dev Prakash

Joined: Oct 09, 2000
Posts: 28
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

Joined: Sep 23, 2000
Posts: 2
Applets does not have constructors instead they have init()
I agree. Here's the link:
subject: JDCert Q - Applet
jQuery in Action, 3rd edition