Forums Register Login

Mock Exam

+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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,
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 731 times.
Similar Threads
Mock Exam
Answer :Run time error / why?
applet question
Applet
Doubts in Applet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:22:35.