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
Which software is used for java programming?
Is java free for commercial?
What is a cup of java?
How do I convert a string to an int in java?
What do you understand by copy constructor in java?
What is the final keyword in java?
What is the difference between static class and normal class?
Explain about field hiding in java?
how come we know the object is no more used in the class?
hr interview how many minutes asking question
What is the difference between compile-time polymorphism and runtime polymorphism?
What is final?
What is difference between float and double?
Why does it take so much time to access an applet having swing components the first time?
What is not thread safe?