Name:     ID: 
 
Email: 

Java Programming Quiz 2

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

A declaration statement can do all the following tasks except ____.
a.
assign an initial value to the variable when declaring a variable
b.
call a constructor to declare an instance of a class when declaring a variable
c.
declare a data type and name an identifier
d.
declare multiple variables with different data types.
 

 2. 

Which of the following obeys the order of operator precedence rules for arithmetic operators (from highest to lowest)?
a.
* , %, +
c.
*, +, %
b.
%, - , /
d.
+, /, %
 

 3. 

Which of the following is not a comparison operator?
a.
=
c.
==
b.
<=
d.
>
 

 4. 

Which of the following is an equality operator?
a.
!=
c.
>=
b.
=
d.
<=
 

 5. 

The ____ method assigns a caption or String to an object.
a.
add()
c.
setForeground()
b.
println()
d.
setText()
 

 6. 

When a call statement is encountered, the Java compiler looks for a matching method in all of the following places except ____.
a.
in the application itself
c.
the imported packages
b.
an external class
d.
the Java SDK
 

 7. 

The ____ statement is an example of a selection structure.
a.
catch
c.
try
b.
if...else
d.
while
 

 8. 

Which of the following is a valid condition for an if statement? Assume the variable "done" is a boolean.
a.
(done=true)
c.
(done == "false")
b.
((done == false) || (done == true))
d.
(done == false && done)
 

 9. 

Which of the following is the logical NOT operator?
a.
!
c.
||
b.
!=
d.
&&
 

 10. 

Which of the following is not a requirement for method arguments and their respective parameters?
a.
An argument and its respective parameter must have the same identifier name.
b.
There must be the same number of arguments as parameters.
c.
The arguments must be in the same order as the parameters.
d.
Each argument must be of the same data type as its respective parameter.
 

 11. 

Which of the following is not a reference type in Java?
a.
array
c.
float
b.
Date
d.
String
 

 12. 

Pressing ____ when a window is active saves an image of the current screen to the Windows Clipboard.
a.
alt+ctrl
c.
alt+print screen
b.
alt+insert
d.
alt+shift
 

 13. 

Which of the following is not a requirement of user-defined methods?
a.
they must be called from other code
c.
they must contain a method header
b.
they must contain a set of braces
d.
they must reside inside a class
 

 14. 

The ____ statement identifies a block of statements that potentially may throw an exception.
a.
catch
c.
throw
b.
finally
d.
try
 

 15. 

The ____ method is triggered when a user clicks an option button in a CheckboxGroup.
a.
addItemListener()
c.
itemStateChanged()
b.
getState()
d.
setState()
 

True/False
Indicate whether the statement is true or false.
 

 16. 

Java allows the programmer to declare a variable as one data type and then later insert another data type into that variable location.
 

 17. 

If several variables of the same data type are declared in a program, the data type can be listed once followed by the variables separated by commas.
 

 18. 

Java cannot compile and execute a program successfully if the program has no code inside the main() method.
 

 19. 

In a method call, parentheses must be included after the method name even if the method sends no arguments.
 

 20. 

The expression, !(a == a), evaluates to true.
 

 21. 

The assignment operator in Java also can be used to represent equality.
 

 22. 

When applets use components to display text boxes, the last text box added to the applet has the focus.
 

 23. 

Return value identifiers must be declared in the body of the method.
 

 24. 

A method's return value and its resulting storage location, if any, must have the same data type and identifier name.
 

 25. 

Applets use the System.exit() method to terminate the program.
 



 
         Start Over