aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock test question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock test question" Watch "Mock test question" New topic
Author

Mock test question

Prasad Ballari
Ranch Hand

Joined: Sep 23, 2000
Posts: 149
Hi,
Following is the code from "John Hunt"
import java.applet.Applet;
import java.awt.*;

public class Sample extends Applet {
private String text = "Hello World";
public void init() {
add(new Label(text));
}
//1 from
public Sample (String string) {
text = string;
}
// 1 to
}
The program gives runtime error.Is it due to abesence of no-argument constructor as JVM calles no-argument constructor..

Program runs without error if you replace //1 from - //1 to by
public Sample(){
super();
}
Pls clarify my doubt..
prasad
------------------

[This message has been edited by Prasad Ballari (edited December 03, 2000).]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
That is a special requirement for applets. It is the responsibility of the browser to create the applet object - this is done by calling the no-args constructor.
An applet constructor with an argument does not make any sense because the programmer has no control over how the constructor is called.
Bill
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
Originally posted by William Brogden:
That is a special requirement for applets. It is the responsibility of the browser to create the applet object - this is done by calling the no-args constructor.
Bill

No Mr Brodgen this is not correct what are you saying.
you are wrong here. any of the browser didn't create thr applet object by calling no args constructor, inspite of it , it is done by init() method. which is having signature like
public void init()
as Mr Prasad Ballari all ready stated that providing an other constructor like
public Sample (String string) {
text = string;
}
didn't create any problum. and according to the rule of
java if any of the class having any constructor then default
constructor will not be provided. so at the presence of
above constructor default no args constructor can't exists.
and above all every browser having a JVM inside that so it has
to follow the java semantics and applet is not an exception.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock test question