Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Java How To Program, 5/e Test Item File 1 of 2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Java How to Program, 5/e Test Item File 1 of 2

Chapter 3

Section 3.2

3.2 Q1: You can start an applet initially by using the appletviewer. The applet can be restarted by using which
of the following Applet menu items?
a.save.
b.quit.
c.tag.
d.reload.
ANS: d. reload.

Section 3.3

3.3 Q1: If ClassA extends ClassB, then


a.ClassA is a superclass.
b.ClassB is a superclass.
c.ClassB is a subclass.
d.ClassB is a derived class.
ANS: b. ClassB is a superclass.

3.3 Q2: Every Java applet or application is composed of at least one:


a.public method
b.data member
c.public class declaration
d.imported class
ANS c. public class declaration

3.3 Q3: The extends keyword creates a new


a.instance
b.subclass
c.baseclass
d.superclass
ANS: b. subclass (the class is derived from the superclass)

3.3 Q4: To draw on an applet, the programmer must access the _____ object in the applet's paint method.
a.drawstring
b.drawLine
c.Graphics
d.Pixel
ANS: c. Graphics

3.3 Q5: When an applet container encounters an HTML file that specifies an applet to execute, the applet container
automatically loads ________ of the applet from the same directory as that of the HTML file.
a.the .java file
b.the .class file
c.the main line
d.the .htm file
ANS: b. the .class file

3.3 Q6: Which of the following will not produce an error when trying to load and run a program with the
appletviewer?
a.Placing additional characters, such as commas, between the components in the <applet> tag.
b.Omitting the ending </applet> tag.
c.Creating an applet that is less than 640 pixels by 480 pixels.
d.Running the appletviewer with a file name that does not end with .html or .htm .
ANS: c. Creating an applet that is less than 640 pixels by 480 pixels.

Section 3.4

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.
Java How to Program, 5/e Test Item File 2 of 2

3.4 Q1: Which method should be used to draw a line of text on an applet?
a.Graphics method drawText.
b.Text method drawLine.
c.Graphics method drawLine.
d.Graphics method drawString.
ANS: d. Graphics method drawString.

3.4 Q2: To draw a single black line from (0, 15) to (20, 25), call the method _________ in the paint method.
a.g.drawLine( 0, 15, 20, 25 );
b.g.drawString( "black", 0, 15 );
c.g.drawLine( 0, 15, 20, 10 );
d.g.drawLine( 15, 0, 25, 20 );
ANS: a. g.drawLine( 0, 15, 20, 25 );

Section 3.5

3.5 Q1: A floating point variable declared as primitive type double has ___ significant digits.
a.12
b.16
c.32
d.15
ANS: d. 15

3.5 Q2: Which of the following import statements will import the Graphics class?
a.import java.awt.Graphics;
b.import java.awt.*
c.import java.swing.Graphics;
d.import java.awt.g;
ANS: a. import java.awt.Graphics; [Note: answer b is not correct because the semicolon (;) is missing.]

3.5 Q3: Assuming the following class declaration:

class SampleClass {
int a;
int b;
AnotherClass q;

public void sampleMethod()


{
int c = 1;
a = c * 7;
b = 32 + c * a;
}
}

which of the following statements is true?


a.c is a reference.
b.a and b are local variables.
c.a and b are declared as a primitive data type.
d.q is declared as a primitive data type.
ANS: c. a and b are declared as a primitive data type.

© Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved.

You might also like