jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock Exam 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 "Mock Exam" Watch "Mock Exam" New topic

Mock Exam


Joined: Jun 14, 2002
Posts: 4
Could someone explain this for me? Thanks in advance.
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;
The HTML page:
//<applet code ="Sample.class" width=200 height=100></applet>

Answer is "Generates a running error"
kevin jia
Ranch Hand

Joined: Jul 13, 2000
Posts: 38
For an applet you can't provide a constructer with arguments.
Marcela Blei
Ranch Hand

Joined: Jun 28, 2000
Posts: 477
For an applet you may provide a constructer with arguments,
but if you want to use it, you have to instantiate the Applet from an application.
When you instatiate and applet from an HTML page the default constructor is called so you must have one. If you need to pass values from the HTML page to the applet you may use the PARAMETER tag in the HTML page and the getParameter() method in your applet code

Joined: Jun 14, 2002
Posts: 4
after I remove the code
public Sample (String string){
text = string;
still get the run time error
my html code like this:
title SampleApplet
applet code="Sample.class" width=200 height=200 /applet
I left the angle blanket out because it'll display nothing
I agree. Here's the link: http://aspose.com/file-tools
subject: Mock Exam
jQuery in Action, 3rd edition