| 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" [This message has been edited by Jim Yingst (edited July 28, 2000).]
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12269
|
|
The convention with browsers as containers of applets is: The browser creates the applet object by calling the no-args constructor. When you provide a constructor with an argument, the compiler will NOT automatically generate a no-args constructor. Therefore the browser attempt to create a Sample object fails. Bill
|
Java Resources at www.wbrogden.com
|
 |
beginner
Greenhorn
Joined: Jun 14, 2002
Posts: 4
|
|
Thanks Bill but after I remove the Sample constructor I still got run time error. Can you run the piece of code and see what's happen? thanks,
|
 |
 |
|
|
subject: Mock Exam
|
|
|