Which two reasons should you use interfaces instead of abstract classes? (Choose two.)
A. You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public.
B. You expect that unrelated classes would implement your interfaces.
C. You want to share code among several closely related classes.
D. You want to declare non-static on non-final fields.
E. You want to take advantage of multiple inheritance of type.
Given the code fragment:
String str = "Java is a programming language"; ToIntFunction
What is the result?
A. 0
B. 1
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Given the code fragment:
BiFunction
What is the result?
A. 20
B. 20.5
C. A compilation error occurs at line n1.
D. A compilation error occurs at line n2.
Given:
class RateOfInterest {
public static void main (String[] args) {
int rateOfInterest = 0;
String accountType = "LOAN";
switch (accountType) {
case "RD";
rateOfInterest = 5;
break;
case "FD";
rateOfInterest = 10;
break;
default: assert false: "No interest for this account"; //line n1 } System.out.println ("Rate of interest:" + rateOfInterest); } }
and the command:
java -ea RateOfInterest
What is the result?
A. Rate of interest: 0
B. An AssertionError is thrown.
C. No interest for this account
D. A compilation error occurs at line n1.
Given the code fragment:
What is the result?
A. 5 : 3 : 6
B. 6 : 5 : 6
C. 3 : 3 : 4
D. 4 : 4 : 4
Given:
Your design requires that:
fuelLevel of Engine must be greater than zero when the start() method is invoked. The code must terminate if fuelLevel of Engine is less than or equal to zero.
Which code fragment should be added at line n1 to express this invariant condition?
A. assert (fuelLevel) : "Terminating...";
B. assert (fuelLevel > 0) : System.out.println ("Impossible fuel");
C. assert fuelLevel < 0: System.exit(0);
D. assert fuelLevel > 0: "Impossible fuel" ;
Given the code fragment:
What is the result?
A. A compilation error occurs at line n1.
B. Checking...
C. Checking... Checking...
D. A compilation error occurs at line n2.
Assume customers.txt is accessible and contains multiple lines.
Which code fragment prints the contents of the customers.txt file?
A. Stream
B. Stream
C. Stream
D. Stream
Given the code fragment:
List
DoubleFunction funD = d ?gt; d + 100.0;
doubles.stream (). forEach (funD); // line n1
doubles.stream(). forEach(e ?gt; System.out.println(e)); // line n2
What is the result?
A. A compilation error occurs at line n2.
B. 200.12
300.32
C. 100.12
200.32
D. A compilation error occurs at line n1.
Given the code fragments:
class Caller implements Callable
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?
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.