• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock Exam

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic