Midterm Revision
Midterm Revision
}
In order to compile this program, the source code should be stored in a file named?
A. Test.class B. Test.doc C. Test.txt
D. Test.java E. Any name with extension .java
15- The extension name of a Java bytecode file is?
A. .java B. .obj
C. .class D. .exe
16- The extension name of a Java source code file is?
A. .java B. .obj
C. .class D. .exe
17- Which of the following lines is not a Java comment?
A. /** comments */ B. // comments
C. -- comments D. /* comments */
18- Which of the following are the reserved words?
A. public B. static C. void D. class
19- Every statement in Java ends with ________?
A. a semicolon (;) B. a comma (,)
C. a period (.) D. an asterisk (*)
20- 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
21- 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
22- Suppose a Scanner object is created as follows:
Scanner input = new Scanner(System.in);
What method do you use to read an int value?
A. input.nextInt(); B. input.nextInteger();
C. input.int(); D. input.integer();
A. $343 B. class
C. 9X E. radius
35- Which of the following are correct names for variables according to Java naming
conventions?
A. radius B. Radius
C. RADIUS D. findArea
A. 1 = x; B. x = 1;
C. x := 1; D. 1 := x;
38- To declare a constant MAX_LENGTH inside a method with value 99.98, you write
A. MAX_VALUE B. Test
C. read D. ReadInt
E. COUNT
40- According to Java naming convention, which of the following names can be variables?
A. FindArea B. findArea
C. totalLength D. TOTAL_LENGTH
E. class
41- Which of these data types requires the most amount of memory?
A. long B. int
C. short D. byte
A. 10 B. 11
C. 11.25 D. 12
A. 1 B. 2
C. 4 D. 0
A. 1 B. 2
C. 4 D. 0
A. 1 B. 2
C. 3 D. 4
A. -1 B. -2 C. -3 D. -4
A. 3 B. -3 C. 4 D. -4
A. 9 B. 8 C. 9.0 D. 8.0
A. 2 B. 2.0
C. 0 D. 1.0
50- The expression 4 + 20 / (3 - 1) * 2 is evaluated to
A. 4 B. 20
C. 24 D. 9
A. 1 + x = x; B. x += 1;
C. x := 1; D. x = x + 1;
E. x = 1 + x;
A. 0 B. 1
C. 2 D. 3
A. 0 B. 1
C. 2 D. -1
number += 1;
number = number + 1;
number++;
++number;
A. Yes B. No
57- Which of the following expressions will yield 0.5?
A. 1 / 2 B. 1.0 / 2
C. (double) (1 / 2) D. (double) 1 / 2
E. 1 / 2.0
A. 2 B. 2.5
C. 3 D. 2.0
59- If you attempt to add an int, a byte, a long, and a double, the result will be a __________
value.
A. byte B. int
C. long D. double
A. 4 B. "4"
C. '\0004' D. '4'
61- Suppose x is a char variable with a value 'b'. What will be displayed by the statement
System.out.println(++x)?
A. a B. b
C. c D. d
A. System.out.println("smith\exam1\test.txt");
B. System.out.println("smith\\exam1\\test.txt");
C. System.out.println("smith\"exam1\"test.txt");
D. System.out.println("smith"\exam1"\test.txt");
A. Yes B. No
65- (’3’ - '2' + 'm' / 'n') is ______.
A. 0 B. 1
C. 2 D. 3
A. Java123 B. Java6
E. Illegal expression
67- Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
A. 66 B. B
C. A1 D. Illegal expression
E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).
A. integer.parseInt(s); B. Integer.parseInt(s);
C. integer.parseInteger(s); D. Integer.parseInteger(s);
A. double.parseDouble(s); B. Double.parsedouble(s);
C. double.parse(s); D. Double.parseDouble(s);
71- Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("It is even!");
}
72- Object-oriented programming allows you to derive new classes from existing classes. This is
called ____________.
A. encapsulation B. inheritance
C. abstraction D. generalization
73- What is the output of the following code?
public class Test1 {
public static void main(String[] args) {
ChildClass c = new ChildClass();
c.print();
}
}
class ParentClass {
int id = 1;
void print() {
System.out.println(id);
}
}
class ChildClass extends ParentClass {
int id = 2;
}
A. 0 B. 1
C. 2 D. Nothing
74- What is the output of the following code?
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}
class Student extends Person {
public String getInfo() {
return "Student";
}
}
class Person {
public String getInfo() {
return "Person ";
}
public void printPerson() {
System.out.print(getInfo());
}
}
A. void B. int
C. double D. public
A. a[2] B. a(2)
C. a[3] D. a(3)
83- The JVM stores the array in an area of memory, called _______, which is used for dynamic
memory allocation where blocks of memory are allocated and freed in an arbitrary order.
A. stack B. heap