PROGRAMMING
2nd Semester
3rd Quarter
Name: _________________________ Date: ______________
Section: ________________________ Score: _____________
1.What is a structure that can store many of the same kind of data together at
once?
A. array C. index
B. element D. list
2.Which is a statement that moves program control to the next statement after the
current structure.
A. break C. default
B. case D. switch
3.The statement int[] names. What does this do?
A. creates an array C. generates a syntax error
B. declares an array variable D. none of the above
4.Which of the following is NOT a comparison operator in Java language?
A. > C. =
B. < D. ==
5.Which Scanner class method is used to read string value from the user?
A. next() C. nextLine()
B. nextString() D. Both A and C
6.What is the general structure of a method?
A. <return value type><method name> (arguments)
B. public static void main (String[ ] args)
C. <modifier><return value type><method name> (parameters)
D. <method name> (parameter)
7.What is making an instance of one class a field in another class?
A. nesting C. aggregation
B. class fielding D. concatenation
8.The Java Virtual Machine (JVM) periodically performs what process, which
automatically removes unreferenced objects from memory?
A. memory cleansing C. garbage collection
B. memory deallocation D. object termination
9.What does CRC stand for?
A. Class, Return Value, Composition
B. Class, Responsibilities, Collaborations
C. Class, Responsibilities, Composition
D. Compare, Return, Continue
10.This type of method cannot access any non-static member variable in its own
class. What is this?
A. instance C. void
B. static D. non-static
11. The code between a pair of braces in a method is called?
A. block C. private
B. head D. null
12. Which of the following could be the last legally coded line of a method declared
as: public static int getVal(double sum)?
A. return 2.5; C. return;
B. return void; D. return 77;
13.What does void mean?
A. Void means that a method returns any value.
B. Void means that a method takes no parameters.
C. Void means that a method returns no value.
D. Void means that a method can take any parameter.
14. What does this method call return?
doubleInt(5);
public int doubleInt(int x)
{
x * 2;
}
A. 10
B. 5
C. this method returns nothing.
D. this method is improperly written.
15.Which of the following is a false statement?
a. A variable of type int can hold any whole number value from approximately
negative two billion to positive two billion.
b. We can use the data types of byte or short to hold larger values than can be
accommodated by an int.
c. When you assign a value to an int variable, we do not type any commas; we
type only digits and an optional plus or minus sign to indicate a positive or
negative integer.
d. none of the above.
16.What kind of loop is the while loop?
A. prefix C. postfix
B. pretest D. posttest
17.What kind of loop is the for loop?
A. prefix C. postfix
B. pretest D. posttest
18.What is a constant that stores a value that is used to signify that a loop should
stop iterating which is also called a flag?
A. accumulator C. meter
B. counter D. sentinel
19.What is a variable that is incremented by a fixed value?
A. accumulator C. meter
B. counter D. sentinel
20. What kind of loop is the do-while loop?
A. prefix C. postfix
B. pretest D. posttest
21.What is stored in x after the code segment is executed?
int x;
x = 10 + 5 % 3;
A. 0 C. 5
B. 11 D. 12
22.Calculate the expression:
(int)(9 % 2 * 7 / 3);
A. 4.67 C. 2.33
B. 4 D. 2
23.What is the returned value of recMethod(5)?
public static int recMethod(int x)
{
if(x==40)
return x;
else
return(x + recMethod(x * 2));
}
A. 68 C. 70
B. 75 D. 82
24.What is the output of the code?
public class Points
{
public static void main(String args[])
{
methodRankPoints(255.7);
}
public static void methodRankPoints(double points)
{
if (points >= 202.5)
System.out.println("Rank:A1");
else if (points >= 122.4)
System.out.println("Rank:A2");
else
System.out.println("Rank:A3");
}
}
A. Rank:A1 C. Rank:A3
B. Rank:A2 D. Rank:A4
25.What output is produced by the following program?
public class Nums
{
public static void main(String args[])
{
int x = 15;
sentence(x, 45);
int y = x - 5;
sentence(y, x + y);
}
public static void sentence(int num1, int num2)
{
System.out.println(num1 + " " + num2);
}
}
A. 15 42 C. 25
10 25 57
B. 57 D. num1 num2
25