aspose file tools*
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
Author

JDCert Q - Applet

vidhya Ramachandran
Greenhorn

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
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
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
Applets does not have constructors instead they have init()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDCert Q - Applet