MultipleChoice
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) throws 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?
OptionsMultipleChoice
Given:
class Vehicle implements Comparable<Vehicle>{
int vno;
String name;
public Vehicle (int vno, String name) {
this.vno = vno,;
this.name = name;
}
public String toString () {
return vno + '':'' + name;
}
public int compareTo(Vehicle o) {
return this.name.compareTo(o.name);
}
and this code fragment:
Set<Vehicle> vehicles = new TreeSet <> ();
vehicles.add(new Vehicle (10123, ''Ford''));
vehicles.add(new Vehicle (10124, ''BMW''));
System.out.println(vehicles);
What is the result?
OptionsMultipleChoice
Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : ''Invalid Denominator'';
int = a / b;
System.out.println (c);
}
}
What is the result of running the code with the --da option?
OptionsMultipleChoice
Which statement is true about the single abstract method of the java.util.function.Predicate interface?
OptionsMultipleChoice
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 FuelNotAvailException {//line n2
super ride ();
}
}
and the code fragment:
public static void main (String[] args) throws Exception {
Vehicle v = new SolarVehicle ();
v.ride();
}
Which modification enables the code fragment to print Happy Journey!?
OptionsMultipleChoice
Given that these files exist and are accessible:
/sports/info.txt
/sports/cricket/players.txt
/sports/cricket/data/ODI.txt
and given the code fragment:
int maxDepth =2;
Stream<Path> paths = Files.find(Paths.get(''/sports''),
maxDepth,
(p, a) -> p.getFileName().toString().endsWith (''txt''),
FileVisitOption.FOLLOW_LINKS);
Long fCount = paths.count();
System.out.println(fCount);
Assuming that there are NO soft-link/symbolic links to any of the files in the directory structure, what is the result?
OptionsMultipleChoice
Given:
What change should you make to guarantee a single order of execution (printed values 1 -100 in order)?
OptionsMultipleChoice
Given the structure of the Student table:
Student (id INTEGER, name VARCHAR)
Given the records from the STUDENT table:
Given the code fragment:
Assume that:
What is the result?
OptionsMultipleChoice
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?
OptionsMultipleChoice
Given:
IntStream stream = IntStream.of (1,2,3);
IntFunction
IntStream newStream = stream.map(inFu.apply(10)); //line n2
newStream.forEach(System.output::print);
Which modification enables the code fragment to compile?
Options