Intermediate Programming

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

____	1.	It is illegal to declare the loop control variable inside the for loop header.

____	2.	The for statement combines counter initialization, condition test and counter update into a single expression.

____	3.	The keyword public indicates that the class is accessible to all potential clients.

____	4.	Both the value of a variable and the type of data it contains can change during execution of a program.

____	5.	It is illegal to declare several variables in a single declaration, i.e.  int a, b, c;

____	6.	The purpose of comments in a program is to document every line of code.

____	7.	m++, m=m+1, and m+=1 are all equivalent expressions.

____	8.	If a single statement follows an if or else statement the braces are not necessary, i.e. 
if( ... )
   statement
else
   statement

____	9.	A while loop will always execute at least once.

____	10.	In Java it is illegal to have two variables referencing the same object.

____	11.	Constructors do not have return types, but all other methods do.

____	12.	A method can only have one return statement.

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

____	13.	Which of the following is NOT a primitive data type in Java?
a.	integer	c.	boolean	
b.	string	d.	character	

____	14.	Which of the following is correct Java for writing exponential, or scientific notation?
a.	3.14	c.	5.124E5	
b.	5 x 10 -1 	d.	none of the above	

____	15.	Which of the following mixed-mode arithmetic expressions yields 8.0?
a.	5 / 2 * 4.0	c.	5.0 / 2 * 4	
b.	5 / 2.0 * 4	d.	5.0 / 2.0 * 4	

____	16.	What type of expression returns either true or false?
a.	Boolean	c.	initialization	
b.	arithmetic	d.	none of the above	

____	17.	Java deletes objects from memory in a process called:
a.	deletion	c.	memory allocation	
b.	garbage collection	d.	memory dumping	

____	18.	Which of the following operators has the highest precedence?
a.	Assignment ( = )	c.	Method Selector ( . )	
b.	Unary Plus ( + )	d.	Subtraction ( - )	

____	19.	The expression 3 + 2 * 5 - 1 yields:
a.	24	c.	11	
b.	12	d.	20	

____	20.	What string results from the expression "1 + 2 = " + 1 + 2
a.	"3 = 3"	c.	"1 + 2 = 12"	
b.	"1 + 2 = 3"	d.	"3 = 12"	

____	21.	Which String class method returns a string's length?
a.	size()	c.	stringLength()	
b.	length()	d.	width()	

____	22.	Which statement provides a looping mechanism that executes statements repeatedly as long as some condition is true?
a.	if 	c.	while	
b.	else	d.	assignment	

____	23.	How many times will the following loop execute?
int counter = 2;
while ( counter < 10 ){
   counter += 2;
}
a.	3	c.	5	
b.	4	d.	0	

____	24.	If class A extends class B, class B is the _________ of class A.
a.	parent	c.	nephew	
b.	child	d.	subclass	

____	25.	Values passed to a method when it is invoked are called:
a.	actual parameters	c.	constructors	
b.	formal parameters	d.	initial values	

Completion
Complete each statement.

	26.	A _________ is an item whose value can change during the execution of a program.

	27.	If a reference variable of an object is set to _______, and no other variable points to that object, the computer reclaims the object's memory during garbage collection.

	28.	Using the visibility modifier __________ for instance variables is an important aspect of information hiding.

	29.	A programmer uses the symbol ______ to refer to the current instance of a class within that class's definition.

Short Answer

	30.	Give an example of a string literal and a floating point literal.

	31.	Write a variable declaration statement for an integer value with the name employeeNumber

	32.	What does the modulus operator ( % ) yield?

	33.	Casting the floating point number 3.8 to an integer using (int)3.8, yields what value.