wood burning stoves*
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
Author

Mock Exam

beginner
Greenhorn

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:
//<html>
//<title>SampleApplet</title>
//<body>
//<applet code ="Sample.class" width=200 height=100></applet>
//</body>
//</html>

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
beginner
Greenhorn

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:
html
title SampleApplet
body
applet code="Sample.class" width=200 height=200 /applet
/body
/html
I left the angle blanket out because it'll display nothing
 
 
subject: Mock Exam
 
Similar Threads
applet
Applet
Doubts in Applet
Mock Exam
Answer :Run time error / why?