(c) planning --> coding --> testing --> analyzing (d) planning --> redefining--> coding--> testing
9. Of the following phases of programming, which is generally the phase on which most time is spent?
(a) Coding
(b) Planning a solution to the problem
(c) Testing and evaluation (d) Defining the problem
10. Valid Java comments include which of the following?
I. II. III.
/* this is an /* embedded */ comment */ /* this is an // embedded // comment */ // this is a comment */
(a) I only (b) I and II only
(c) I and III only (d) II and III only
11. What is the name of the class whose definition is begun by the
following line?
public class Hello extends Greeting (a) Hello
(b) Greeting.Hello
(c) Hello.Greeting (d) Greeting
12. Which of the following is a Java statement that imports classes
in the package java.sql?
(a) import java.sql.all; (b) import all java.sql;
(c) import java.sql.*; (d) import java.sql;
13. The following is a Java program segment:
public void paint (Graphics g) {
int x = 10; int y = 20;
paintPicture( g, x, y); }
public void paintPicture(Graphics g, int a, int b) {
g.setColor(Color.red); // more code follows }
What will be the value of the parameter \paintPicture when this code is executed? (a) 20
(b) This will not compile. This is an error because the parameter
\
(c) 10 (d) 0
14. Which of the following statements is (are) true about debugging
and testing servlets?
I. II.
After a change is made to a servlet, the servlet must be
recompiled for the change to take effect. Modifying the parameters of calls to the method out.println can change the HTML in the response of a servlet.
(a) I only
(b) II only (c) I and II (d) None
15. A Java servlet can be declared with the type of content it will produce, such as image/gif or text/html, by using a call to which
of the following methods of HttpServletResponse?
(a) setContentType (b) resetBuffer
(c) addCookie (d) encodeURL
16. Consider a Java source file that begins with the following line.
import javax.servlet.http.*;
In this file, which of the following lines of code can introduce a valid definition for a Java servlet class named Welcome? (a) public class Welcome extends HttpServlet (b) servlet class Welcome
(c) public servlet Welcome extends HttpServlet (d) new Welcome extends HttpServlet
17. Which of the following is (are) true regarding the Java API
documentation?
I. II.
Programmers can view it on the web.
It consists solely of Java classes and methods.
(a) II only
(b) I and II (c) I only
(d) None
Take Assessment: Multiple-Choice Quiz 5 1. In Java, which of the following is true about constructors?
(a) Constructors must be declared for every class. (b) Constructors can only accept primitive Java types as
parameters.
(c) Constructors cannot return a value.
(d) Constructors can only return 0 or a negative integer.
2. What operator is used to allocate storage for objects?
(a) new (b) =
(c) init (d) ==
3. Which of the following variable names conforms to Java naming
conventions?
(a) fuelRemaining (b) FuelRemaining
(c) AmountOfFuelRemainingInTheTank (d) fuel_remaining
4. Which of the following is (are) consistent with Java naming
conventions regarding capitalization?
I. II. III.
int numPeople; int Counter;
class serviceElevator{}
(a) I only
(b) None
(c) I and III only (d) I, II, and III
5. If variable br references an instance of the class
java.io.BufferedReader, which of the following statements is a
legal call to the method readLine of the class?
(a) br(readLine); (b) br.readLine();
(c) br.readLine; (d) readLine(br);
6. Valid method definitions in Java include which of the following?
I. II. III.
public method myMethod() {} public void myMethod(int i) {} public void myMethod {}
(a) II only (b) None
(c) II and III only (d) I only
7. Suppose you are given a class called List which has print as one of its methods and a correctly instantiated object called myList.
Which of the following could be a valid call to the print method?
(a) print.myList(); (b) print(List);
(c) myList.print(); (d) myList.print;