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"
[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: 12760
    
    5
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
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,
 
Consider Paul's rocket mass heater.
 
subject: Mock Exam
 
Similar Threads
Applet
Doubts in Applet
Mock Exam
applet question
Answer :Run time error / why?