created 01/22/00

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 a 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 Applet

a. java.applet.Applet
b. java.util
c. java.awt.*

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     Back to the main menu.