Professional Documents
Culture Documents
Advanced Programming Languages - CS 2nd Level Sheet 1
Advanced Programming Languages - CS 2nd Level Sheet 1
a- Compiles fine but throws an exception on the run time b- Compiler Error c-Compiles & runs fine
All exceptions in Java are objects. Therefore, they can be generated not only automatically in the
event of an exceptional situation, but also created by the developer.
catch is a keyword to mark the beginning of a block of code intended to catch and handle exceptions.
throws is a keyword that is written in the method signature, and means that the method can potentially
throw an exception with the specified type.
The general view of the construction for “catching” an exceptional situation is as follows:
try{
//here is the code that could potentially lead to an error }
b. Applet is initialized,started,painted,stopped,destroyed
c. Applet is painted,started,stopped,initilaized,destroyed
An Applet is a special type of program that is embedded in the webpage to generate the dynamic content.
An applet is part of a web page, just like an image or hyperlink.
It runs inside the browser and works at client side.
Advantages of an applet:
Initialization: public void init(): is used to initialized the Applet. It is invoked only once.
Start: public void start(): is invoked after the init() method or browser is maximized. It is used to start the
Applet.
Paint: public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can
be used for drawing oval, rectangle, arc etc.
Stop: public void stop(): is used to stop the Applet. It is invoked when Applet is stop or browser is
minimized.
Destroy: public void destroy(): is used to destroy the Applet. It is invoked only once.
3- Answer: c
Explanation: To implement the method drawString we need first need to define abstract method of AWT
that is paint() method. Without paint() method we can not define and use drawString or any Graphic class
methods.
4- Answer: c
5- Answer: b