Given the code fragment:
class CallerThread implements Callable<String> {
String str;
public CallerThread(String s) {this.str=s;}
public String call() throws Exception {
return str.concat(“Call”);
}
}
and
public static void main (String[] args) throws InterruptedException, ExecutionException
{
ExecutorService es = Executors.newFixedThreadPool(4); //line n1
Future f1 = es.submit (newCallerThread(“Call”));
String str = f1.get().toString();
System.out.println(str);
Which statement is true?
A.
The program prints Call Call and terminates
B.
The program prints Call Call and does not terminate.
C.
A compilation error occurs at line n1.
D.
An ExecutionException is thrown at run time.
The program prints Call Call and does not terminate.
Given the for loop construct:
for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?
A.
This is not the only valid for loop construct; there exits another form of for loop
constructor.
B.
The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop
begin.
C.
When expr2 evaluates to false, the loop terminates. It is evaluated only after each
iteration through the loop.
D.
The expression expr3 must be present. It is evaluated after each iteration through the
loop.
The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop
begin.
When expr2 evaluates to false, the loop terminates. It is evaluated only after each
iteration through the loop.
The for statement have this forms:
for (init-stmt; condition; next-stmt) {
body
}
There are three clauses in the for statement.
The init-stmt statement is done before the loop is started, usually to initialize an iteration
variable.
The condition expression is tested before each time the loop is done. The loop isn't
executed if the boolean expression is false (the same as the while loop).
The next-stmt statement is done after the body is executed. It typically increments an
iteration variable.
Given:
What is the result?
A.
100
210
B.
Compilation fails due to an error in line n1
C.
Compilation fails due to an error at line n2
D.
Compilation fails due to an error at line n3
Compilation fails due to an error at line n2
Given:
class FuelNotAvailException extends Exception { }
class Vehicle {
void ride() throws FuelNotAvailException {//line n1
System.out.println(“Happy Journey!”);
}
}
class SolarVehicle extends Vehicle {
public void ride () throws Exception {//line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws FuelNotAvailException, Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?
A.
Replace line n1 with public void ride() throws FuelNotAvailException {
B.
Replace line n1 with protected void ride() throws Exception {
C.
Replace line n2 with void ride() throws Exception {
D.
Replace line n2 with private void ride() throws FuelNotAvailException {
Replace line n1 with protected void ride() throws Exception {
Given:
public class ScopeTest {
int j, int k;
public static void main(String[] args) {
ew ScopeTest().doStuff(); }
void doStuff() {
nt x = 5;
oStuff2();
System.out.println("x");
}
void doStuff2() {
nt y = 7;
ystem.out.println("y");
or (int z = 0; z < 5; z++) {
ystem.out.println("z");
ystem.out.println("y");
}
Which two items are fields?
A.
j
B.
k
C.
x
D.
y
E.
z
j
k
Page 6 out of 26 Pages |
Previous |