Given: java
Runnable task1 = () -> System.out.println("Executing Task-1"); Callable
System.out.println("Executing Task-2"); return "Task-2 Finish.";
};
ExecutorService execService = Executors.newCachedThreadPool();
// INSERT CODE HERE
execService.awaitTermination(3, TimeUnit.SECONDS); execService.shutdownNow();
Which of the following statements, inserted in the code above, printsboth:
"Executing Task-2" and "Executing Task-1"?
Correct Answer:
GH
What do the following print? java
public class DefaultAndStaticMethods { public static void main(String[] args) { WithStaticMethod.print();
}
}
interface WithDefaultMethod { default void print() { System.out.print("default");
}
}
interface WithStaticMethod extends WithDefaultMethod { static void print() {
System.out.print("static");
}
}
Correct Answer:
D
Given: java
Map
What is the output of the given code fragment?
Correct Answer:
F
Given: java
public class SpecialAddition extends Addition implements Special { public static void main(String[] args) {
System.out.println(new SpecialAddition().add());
}
int add() {
return --foo + bar--;
}
}
class Addition { int foo = 1;
}
interface Special { int bar = 1;
}
What is printed?
Correct Answer:
E
Given: java
interface Calculable { long calculate(int i);
}
public class Test {
public static void main(String[] args) { Calculable c1 = i -> i + 1; // Line 1 Calculable c2 = i -> Long.valueOf(i); // Line 2
Calculable c3 = i -> { throw new ArithmeticException(); }; // Line 3
}
}
Which lines fail to compile?
Correct Answer:
G