Can Applet have constructors?

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


Please Help Members By Posting Answers For Below Questions

What is immutable state?

507


How does map works in java?

517


What is sortedset in java?

573


What do you understand by copy constructor in java?

490


Explain the features of java?

593






What do you understand by the term polymorphism?

626


What is the exception hierarchy in java?

483


What does java edition mean?

533


How to create a fecelet view?

555


What is the simpletimezone class in java programming?

536


What does flagged out mean?

573


What is the meaning of immutable regarding string?

520


What do you mean by buffering?

550


What is singleton pattern?

553


What is a control variable example?

529