OOP Midterm Exam

Is this your test? Login to manage it. If not, you can make a test just like it.

This is a non-interactive preview of the quiz content.

1.
1 point
In a format specifier, if the flag is set to 'l', then the output of the result is left justified.
2.
1 point
The class JOptionPane allows a programmer to use graphical interface components to obtain input from a user.
3.
1 point
Which of the following is a valid char value?
4.
1 point
Which of the following is not a logical operator?
5.
1 point
Suppose that you have the following code.

int num = 10;

if (num > 10)
System.out.println(num);
else
System.out.println(num + 5);

The output of this code is 5.
6.
1 point
Including a semicolon before the action statement in a one-way selection causes a syntax error.
7.
1 point
The value of the expression Integer.parseInt("+782") is "782".
8.
1 point
What is the output of the following Java code?

int x = 0;
if (x > 0)
System.out.println("positive ");
System.out.println("zero ");
System.out.println("negative");
9.
1 point
In Java, || has a higher precedence than &&.
10.
1 point
If a = 4; and b = 3;, then after the statement a = b; executes, the value of b is 4 and the value of a is 3.
11.
1 point
The showMessageDialog method has ____ parameter(s).
12.
1 point
JTextFields are used to get input, but not show output.
13.
1 point
Which package is automatically imported by the Java system?
14.
1 point
Which of the following will cause a syntax error?
15.
1 point
Given

char ch;
int num;
double pay;

Which of the following assignment statements are valid?

(i) ch = '*';
(ii) pay = num * pay;
(iii) rate * 40 = pay;
16.
1 point
The class Container is included in the package java.awt.
17.
1 point
Which of the following statements about a named constant is NOT true?
18.
1 point
In Java, extends is a reserved word.
19.
1 point
Whenever there is a superclass-subclass relationship, the superclass inherits all data members and methods of the subclass.
20.
1 point
All switch structures include default cases.
21.
1 point
Suppose that x is an int variable. Which of the following expressions always evaluates to false?
22.
1 point
The output of the Java code:

int alpha = 5;
int beta = 4;

switch (beta)
{
case 2:
alpha = alpha + 2;
case 4:
alpha = alpha + 4;
break;
case 6:
alpha = alpha + 6;
default:
alpha = alpha + 10;
}
System.out.print(alpha);

is: 9
23.
1 point
The symbol >= is a logical operator.
24.
1 point
JTextFields are used to get input, but not show output.
25.
1 point
An expression such as str.length(); is an example of a(n) ____.
26.
1 point
Suppose P and Q are logical expressions. The expression P || Q is true if both P and Q are true.
27.
1 point
The class JFrame contains the method setSize.
28.
1 point
String sentence;
String str1, str2, str3, str4;
int length1;

sentence = "First exam is on Monday.";

str1 = sentence.substring(6, 12);
str2 = str1.substring(0, 4);
str3 = sentence.replace('i', '#');
str4 = sentence.indexOf("on");

length1 = sentence.length();

Based on the code above, what is the value of length1?
29.
1 point
Which of the following is NOT a relational operator in Java?
30.
1 point
String variables are reference variables.
31.
1 point
The standard output object in Java is ____.
32.
1 point
Consider the following program.

public class CircleArea
{
static Scanner console = new Scanner(System.in);
static final float PI = 3.14;

public static void main(String[]args)
{
float r;
float area;
r = console.nextDouble();
area = PI * r * r;
System.out.println("Area = " + area);
}
}

To successfully compile this program, which of the following import statement is required?
33.
1 point
Consider the following statements.

double x;
String y;

y = String.format("%.2f", x);

If x = 285.679, what is the value of y?
34.
1 point
The data type float is a floating-point data type.
35.
1 point
The operators = and == have the same order of precedence.
36.
1 point
Every window has a title, width, and height.
37.
1 point
The height and width of a window are measured in inches.
38.
1 point
Which statement instructs a program to run the garbage collector?
39.
1 point
Based on the code in #11, what is the value of str3?
40.
1 point
When evaluating a mixed expression, all integer operands are converted to floating-point numbers with the decimal part of zero.
41.
1 point
Given the declaration,

Integer x;

After executing either of the following two statements, x points to an Integer object with value 8:

x = 8;

x = new Integer(8);
42.
1 point
Which of the following is a valid Java identifier?
43.
1 point
Based on the code in #11, what is the value of str4?
44.
1 point
In Java, case and switch are reserved words, but break is not a reserved word.
45.
1 point
Which of the following is a valid int value?