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
Differece between class and generic class?
When would you use a static class?
What is the difference between yielding and sleeping in java programming?
How can we create an immutable class in java?
How does linkedhashmap work in java?
Is there a jre for java 11?
What is protected access modifier?
How do you achieve singleton?
What is linkedlist in java?
Can we inherit a class with private constructor?
What is sortedmap interface?
What is rule of accessibility in java?
What does nextint () do in java?
What is the use of static methods?
What are the legal parameters?