Answer Posted / sunil dhadwe
In Java, every class has constructor, so Applet class also has constructor which is invoked when Applet object is created by browser or Applet Viewer. Usually we don't need constructor as we don't create Applet object.
To write applet we write our own class that extends Applet, so our class also becomes Applet. Our class can also have constructor. From our class we can call super class (Applet) constructor. Look at following code:
import java.applet.Applet;
import java.awt.Graphics;
/*
<applet code="AppletConst" width=400 height=300>
</applet>
*/
public class AppletConst extends Applet {
public AppletConst() {
super(); // no compilation error : means Applet class has constructor
System.out.println("Applet constructor");
}
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}
| Is This Answer Correct ? | 39 Yes | 3 No |
Post New Answer View All Answers
What is the difference between the ">>" and " >>>" operators in java?
What is the base class in java from which all classes are derived?
Is math an abstract class in java?
What is a parameter in a function?
Which is bigger float or double java?
How we can declare a static variable?
When does a class need a virtual destructor?
What is the purpose of assert keyword used in jdk1.4.x?
Define class?
What are different types of inner classes ?
How do you sort a string in alphabetical order in java?
Why is method overloading not possible by changing the return type in java?
What is connection class in java?
What is hash table in java?
What is difference between variable declaration and definition?