Which statement is true about java.util.stream.Stream?
A.
A stream cannot be consumed more than once.
B.
The execution mode of streams can be changed during processing.
C.
Streams are intended to modify the source data.
D.
A parallel stream is always faster than an equivalent sequential stream
The execution mode of streams can be changed during processing.
Given:
interface Rideable {Car getCar (String name); }
class Car {
private String name;
public Car (String name) {
this.name = name;
}
}
Which code fragment creates an instance of Car?
A.
Car auto = Car (“MyCar”): : new;
B.
Car auto = Car : : new;
Car vehicle = auto : : getCar(“MyCar”);
C.
Rideable rider = Car : : new;
Car vehicle = rider.getCar(“MyCar”);
D.
Car vehicle = Rideable : : new : : getCar(“MyCar”);
Rideable rider = Car : : new;
Car vehicle = rider.getCar(“MyCar”);
Given the code fragments:
class Caller implements Callable<String> {
String str;
public Caller (String s) {this.str=s;}
public String call()throws Exception { return str.concat (“Caller”);}
}
class Runner implements Runnable {
String str;
public Runner (String s) {this.str=s;}
public void run () { System.out.println (str.concat (“Runner”));}
}
and
public static void main (String[] args) InterruptedException, ExecutionException {
ExecutorService es = Executors.newFixedThreadPool(2);
Future f1 = es.submit (new Caller (“Call”));
Future f2 = es.submit (new Runner (“Run”));
String str1 = (String) f1.get();
String str2 = (String) f2.get();//line n1
System.out.println(str1+ “:” + str2);
}
What is the result?
A.
The program prints:
Run Runner
Call Caller : null
And the program does not terminate.
B.
The program terminates after printing:
Run Runner
Call Caller : Run
C.
A compilation error occurs at line n1.
D.
An Execution is thrown at run time.
The program prints:
Run Runner
Call Caller : null
And the program does not terminate.
Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, “Java Programing”);
Book b2 = new Book (102, “Java Programing”);
System.out.println (b1.equals(b2)); //line n2
Which statement is true?
A.
The program prints true.
B.
The program prints false.
C.
A compilation error occurs. To ensure successful compilation, replace line n1 with:
boolean equals (Book obj) {
D.
A compilation error occurs. To ensure successful compilation, replace line n2 with:
System.out.println (b1.equals((Object) b2));
A compilation error occurs. To ensure successful compilation, replace line n1 with:
boolean equals (Book obj) {
Given the definition of the Vehicle class:
Class Vehhicle {
int distance;//line n1
Vehicle (int x) {
this distance = x;
}
public void increSpeed(int time) {//line n2
int timeTravel = time;//line n3
class Car {
int value = 0;
public void speed () {
value = distance /timeTravel;
System.out.println (“Velocity with new speed”+value+”kmph”);
}
}
new Car().speed();
}
}
and this code fragment:
Vehicle v = new Vehicle (100);
v.increSpeed(60);
What is the result?
A.
Velocity with new speed
B.
A compilation error occurs at line n1.
C.
A compilation error occurs at line n2.
D.
A compilation error occurs at line n3.
Velocity with new speed
Page 4 out of 26 Pages |
Previous |