created: 01/22/00; revised: 10/04/03, 02/12/06

Quiz on Applet Examples

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.

1. What must be imported to get class JApplet

A.    javax.swing.JApplet
B.    java.util.*
C.    java.Applet

2. What must be imported to get most graphics components?

A.    java.Graphics
B.    java.awt.*
C.    java.util.*
D.    java.*

3. To draw a rectangle filled in with the current color use this method:

A.    drawRect()
B.    fillRect()
C.    drawOval()
D.    fillOval()

4. What is the meaning of final in a declaration: final int width = 350;

A.    width is a loop control variable that will finally reach 350.
B.    width gets the value 350 then never changes.
C.    width is the last variable in the list of variables.
D.    width shadows a similar instance variable.

5. If you are using the Graphics object gr and wish to change the pen color to red, what should you do?

A.    gr.setColor( )
B.    gr.setPen( )
C.    setBackground( )
D.    gr.setRed( )

6. If a particular value is needed inside a loop, but never changes, where should it be calculated?

A.    Inside the loop just before it is needed.
B.    Outside of the loop, before the loop in the source code.
C.    Outside of the loop, after the loop in the source code.
D.    Inside the loop as part of the condition that is tested.

7. What method call is used to draw a line from X=20, Y=30 to X=70, Y=50

A.    gr.drawLine( 20, 70, 30, 50 );
B.    gr.drawLine( 20, 30, 70, 50 );
C.    gr.drawLine( 20, 30, 50, 70 );
D.    gr.drawLine( (20, 30), (70, 50) );

8. What HTML tags should begin and end a web page?

A.    <applet>   </applet>
B.    <body>   </body>
C.    <h1>   </h1>
D.    <html>   </html>

9. What method of your applet is called by the browser when it wishes to display it on the monitor?

A.    paint()
B.    drawLine()
C.    setBackground()
D.    setColor()

10. Can the source code for your applet be compiled by the usual javac compiler?

A.    No---because applets have no main()
B.    No---the web browser compiles the code.
C.    Yes---an applet is just another class as far as the compiler is concerned.
D.    Yes---if you are going to run it from the DOS prompt.

The number you got right:       Percent Correct:       Letter Grade:   

Click here

If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.