Java Reviewewr
Java Reviewewr
Instructions:
1. Answer this test in 1 hour.
2. Cellphones, tablets, or the likes should be turned off.
3. No chatting with seatmates.
4. Answers should be clearly written.
5. Direct your questions to your PROCTOR.
6. Avoid erasure(s).
Test I. Multiple-Choice. Write only the letter of the correct answer.
1. What is the range of data type short in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
2. What is the range of data type byte in Java?
a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
3. Which of the following are legal lines of Java code?
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct.
4. An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
5. Which data type value is returned by all transcendental math functions?
a) int
b) float
c) double
d) long
6. What is the output of this program?
class conversion {
public static void main(String args[])
{
double a = 295.04;
int b = 300;
byte c = (byte) a;
byte d = (byte) b;
System.out.println(c + " " + d);
}
}
a) 38 43
b) 39 44
c) 295 300
d) 295.04 300
7. What is the output of this program?
class increment {
public static void main(String args[])
{
int g = 3;
System.out.print(++g * 8);
}
}
a) 25
b) 24
c) 32
d) 33
8. What is the numerical range of a char in Java?
a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535
9. Which of these values can a boolean variable contain?
a) True & False
b) 0 & 1
c) Any integer value.
d) Both a & b
10.
11.
a) 0
b) 1
c) true
d) false
12.
13.
14. With x = 0, which of the following are legal lines of Java code for changing the
value of x to 1?
1.
x++;
2.
x = x + 1;
3.
x += 1;
4.
x =+ 1;
a) 1, 2 & 3
b) 1 & 4
c) 1, 2, 3 & 4
d) 3 & 2
15. Decrement operator, , decreases value of variable by what number?
a) 1
b) 2
c) 3
d) 4
16.
17.
18.
int var3 = 1 + 5;
int var4 = var3 / 4;
System.out.print(var2 + " " + var4);
}
}
a) 1 1
b) 0 1
c) 1.5 1
d) 1.5 1.0
19.
20.
21.
c = ++b;
d = a++;
c++;
b++;
++a;
System.out.println(a + " " + b + " " + c);
}
}
a) 3 2 4
b) 3 2 3
c) 2 3 4
d) 3 4 4
22.
23.
24.
25.
String in Java is a?
a) class
b) object
c) variable
d) character array
26.
{
String obj = "I" + "like" + "Java";
System.out.println(obj);
}
}
a) I
b) like
c) Java
d) IlikeJava
27.
28.
29.
30.
33.
34.
35.
36.
37. Which of the following statements is correct to display Welcome to Java on the
console? (Choose two)
a) System.out.println('Welcome to Java');
b) System.out.println("Welcome to Java");
c) System.println('Welcome to Java');
d) System.out.print("Welcome to Java");
38.
39.
40.
41.
42.
Which of the following are the reserved words? (Choose all possible answer)
a) public
b) static
c) void
d) class
43. To use Scanner in your program, you may import it using: (Choose all possible
answer)
a) import javax.util.Scanner;
b) import java.util.Scanner;
c) import javax.util.Scanner;
d) import java.util.*;
44.
45. If a program compiles fine, but it produces incorrect result, then the program
suffers __________.
a) a compilation error
b) a runtime error
c) a logic error
d) none of these errors
46. If you forget to put a closing quotation mark on a string, what kind error will be
raised?
a) a compilation error
b) a runtime error
c) a logic error
d) relative error
47.
48.
5.7
5.6
5
6
50.
If you enter 1 2 3, when you run this program, what will be the output?
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}
A. 1.0
B. 2.0
C. 3.0
D. 4.0
51.
52. Which of the following are correct names for variables according to Java naming
conventions? (Choose all that applies)
A. radius
B. Radius
C. RADIUS
D. findArea
53.
54.
55.
56.
To declare a constant MAX_LENGTH inside a method with value 99.98, you write
A. final MAX_LENGTH = 99.98;
B. final float MAX_LENGTH = 99.98;
C. double MAX_LENGTH = 99.98;
D. final double MAX_LENGTH = 99.98;
10
B. Test
C. read
D. ReadInt
58.
59.
60.
61.
11
A. number += sum;
B. number = sum + number;
C. sum += number;
D. sum = sum + number;
65. Suppose x is 1. What is x after x += 2?
A. 0
B. 1
C. 2
D. 3
66. What is x after the following statements?
int x = 2;
int y = 1;
x *= y + 1;
A. x is 1.
B. x is 2.
C. x is 3.
D. x is 4.
67. What is the value of i printed?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = ++j + j * 5;
System.out.println("What is i? " + i);
}
}
A. 0
B. 1
C. 5
D. 6
68. What is the value of i printed in the following code?
public class Test {
public static void main(String[] args) {
int j = 0;
int i = j++ + j * 5;
System.out.println("What is i? " + i);
}
}
12
A. 0
B. 1
C. 5
D. 6
69. What is y displayed in the following code?
public class Test {
public static void main(String[] args) {
int x = 1;
int y = x++ + x;
System.out.println("y is " + y);
}
}
A. y is 1.
B. y is 2.
C. y is 3.
D. y is 4.
70. Which of the following assignment statements is illegal?
A. float f = -34;
B. int t = 23;
C. short s = 10;
D. int t = (int)false;
13