Sunteți pe pagina 1din 2

Yourname:__________________________

1. Which of the following is the correct operator


for the NOT function?
A. ||
B. &&
C. !!
D. |
E. &
F. !
2. In Java, object classes are templates from
which instances are created. True or False?
A. True
B. False

3. The online Java API has... (Choose all that


apply)
A. Documentation about Java Classes
provided with the JDK
B. Documentation about user created
classes that have been uploaded
C. Descriptions of methods and constructors
for all classes in the API
D. Documentation about Java language
constructs and keywords

4. Which Java programming construct is


emulated by the ternary operator?
A. While loop
B. Class definition
C. If-Else
D. Method definition
E. Main method
5. Which Java programming construct is
emulated by the switch statement?
A. While loop
B. Class definition
C. If-Else
D. Method definition
E. Main method

6. Reading user input and testing it for valid


values is best accomplished by which loop in
Java?
A. While
B. Do-While
C. For
7. Performing a task a specific number of times
in Java is best accomplished with what loop?
A. While
B. Do-While
C. For

Grade:___________

8. The 3rd expression in the definition of a For


loop must always use either the ++ or the -operator. True or False?
A. True
B. False
9. Which of the following problems in a Java
program will not cause the program to crash?
A. Syntax error
B. Logic error
C. Unhandled thrown exception
10. Static variables are instance variables that
cannot have their values changed. True or
False?
A. True
B. False
11. Static methods allow ordinary methods to be
executed at compile time. True or False?
A. True
B. False
12. Given the code:
1
2
3
4
5
6
7

int [] a = {1,2,3,4,5,6};
int i = a.length - 1;
while(i>=0){
System.out.print(a[i]);
i--;
}

What is the result?


A. 123456
B. ArrayIndexOutOfBounds will be thrown
C. 654321
D.
E. 12345
13. Choose the three legal identifiers.
A. 1stName
B. _4_
C. @name
D. $
E. getSize
14.
Given the code:
1
2
3
4
5

int i = 10;
while (i++ <= 10) {
i++;
}
System.out.print(i);

What is the result?


A. 10
B. 11
C. 12
D. Line 5 will be never reached.


Yourname:__________________________

15. Given the code:


1
2
3
4
5
6
7
8
9
10
11
12

public class Test {


int a = 10;
public void doStuff(int a) {
a += 1;
System.out.println(++a);
}
public static void main(String args[]) {
Test t = new Test();
t.doStuff(3);
}
}

What is the result?


A. 4
B. 5
C. 12
D. 11
16. Given the code:
1
2
3
4
5

int i = 10;
while (++i <= 10) {
i++;
}
System.out.print(i);

What is the result?


A. 10
B. 11
C. 12
D. Line 5 will be never reached.
17.
Given the code:
1
2
3
4
5
6
7
8
9
10

public static void main(String args[]) {


String str = null;
if (str.length() == 0) {
System.out.print("1");
} else if (str == null) {
System.out.print("2");
} else {
System.out.print("3");
}
}

What is the result?


A. Compilation fails.
B. "1" is printed.
C. "2" is printed.
D. "3" is printed.
E. An exception is thrown at runtime.
Write your comments (optional):

Grade:___________

18.
Given the code:
1
2
3
4
5

package com.mycompany;
public class Hotel {
public int roomNr = 100;
}

What can directly access and change the value of


the variable roomNr?
A. Only the Hotel class.
B. Any class.
C. Any class in com.mycompany package.
D. Any class that extends Hotel.
19.
Given the code:
1
2
3
4
5

package com.mycompany;
public class Hotel {
private int roomNr = 100;
}

What can directly access and change the value of


the variable roomNr?
A. Only the Hotel class.
B. Any class.
C. Any class in com.mycompany package.
D. Any class that extends Hotel.
20.
Given the code:
1
2
3
4
5
6
7
8
9
10
11
12

public class Room {


public int roomNr;
private Date beginDtm;
private Date endDttm;
public void book(int roomNr,
Date beginDttm, Date endDttm) {
this.roomNr = roomNr;
this.beginDtm = beginDttm;
this.endDttm = endDttm;
}
}

What is true?
A. The code demonstrates polymorphism.
B. The class is fully encapsulated.
C. The variable roomNr breaks
encapsulation.
D. Variables beginDttm and endDttm break
polymorphism.
E. The method book breaks encapsulation.

S-ar putea să vă placă și