Which method is called first by an applet program ?
2014
Which method is called first by an applet program ?
- A.
start( )
- B.
run( )
- C.
init( )
- D.
begin( )
Attempted by 422 students.
Show answer & explanation
Correct answer: C
Answer: init()
Explanation: init() is the first lifecycle method called by the applet container when the applet is loaded. It is intended for one-time initialization tasks such as setting up variables or loading resources.
init(): Called once when the applet is first loaded; use this for one-time setup.
start(): Called after init() and each time the applet becomes active; use this to start or resume execution (e.g., start animations).
paint(Graphics g): Called to render the applet’s output on screen.
stop(): Called when the applet is no longer visible; use this to pause ongoing activity.
destroy(): Called when the applet is being removed; use this to free resources and perform cleanup.
Note: run() is not part of the standard applet lifecycle. It is associated with thread execution when an applet implements Runnable and is invoked by the thread scheduler rather than by the applet container.