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?
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");
}
}
Given:
java
public static void main(String[] args) {
try {
throw new IOException();
} catch (IOException e) {
throw new RuntimeException();
} finally {
throw new ArithmeticException();
}
}
What is the output?
Given:
java
public class ThisCalls {
public ThisCalls() {
this(true);
}
public ThisCalls(boolean flag) {
this();
}
}
Which statement is correct?
Given:
java
var lyrics = """
Quand il me prend dans ses bras
Qu'il me parle tout bas
Je vois la vie en rose
""";
for ( int i = 0, int j = 3; i < j; i++ ) {
System.out.println( lyrics.lines()
.toList()
.get( i ) );
}
What is printed?
Given:
java
var now = LocalDate.now();
var format1 = new DateTimeFormatter(ISO_WEEK_DATE);
var format2 = DateTimeFormatter.ISO_WEEK_DATE;
var format3 = new DateFormat(WEEK_OF_YEAR_FIELD);
var format4 = DateFormat.getDateInstance(WEEK_OF_YEAR_FIELD);
System.out.println(now.format(REPLACE_HERE));
Which variable prints 2025-W01-2 (present-day is 12/31/2024)?
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?
Given:
java
import java.io.*;
class A implements Serializable {
int number = 1;
}
class B implements Serializable {
int number = 2;
}
public class Test {
public static void main(String[] args) throws Exception {
File file = new File("o.ser");
A a = new A();
var oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(a);
oos.close();
var ois = new ObjectInputStream(new FileInputStream(file));
B b = (B) ois.readObject();
ois.close();
System.out.println(b.number);
}
}
What is the given program's output?
Given:
java
public class OuterClass {
String outerField = "Outer field";
class InnerClass {
void accessMembers() {
System.out.println(outerField);
}
}
public static void main(String[] args) {
System.out.println("Inner class:");
System.out.println("------------");
OuterClass outerObject = new OuterClass();
InnerClass innerObject = new InnerClass(); // n1
innerObject.accessMembers(); // n2
}
}
What is printed?
Given:
java
public class Test {
public static void main(String[] args) throws IOException {
Path p1 = Path.of("f1.txt");
Path p2 = Path.of("f2.txt");
Files.move(p1, p2);
Files.delete(p1);
}
}
In which case does the given program throw an exception?
Given:
java
DoubleStream doubleStream = DoubleStream.of(3.3, 4, 5.25, 6.66);
Predicate
System.out.println(doubleStream.anyMatch(doublePredicate));
What is printed?
Given:
java
List
.boxed()
.toList();
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
cannesFestivalfeatureFilms.stream()
.limit(25)
.forEach(film -> executor.submit(() -> {
System.out.println(film);
}));
}
What is printed?
What does the following code print?
java
import java.util.stream.Stream;
public class StreamReduce {
public static void main(String[] args) {
Stream
System.out.print(stream.reduce(String::concat));
}
}
Which of the following methods of java.util.function.Predicate aredefault methods?
Given:
java
interface A {
default void ma() {
}
}
interface B extends A {
static void mb() {
}
}
interface C extends B {
void ma();
void mc();
}
interface D extends C {
void md();
}
interface E extends D {
default void ma() {
}
default void mb() {
}
default void mc() {
}
}
Which interface can be the target of a lambda expression?
Given:
java
List
List
Collections.copy(l1, l2);
l2.set(0, "d");
System.out.println(l1);
What is the output of the given code fragment?
Given:
java
Object myVar = 0;
String print = switch (myVar) {
case int i -> "integer";
case long l -> "long";
case String s -> "string";
default -> "";
};
System.out.println(print);
What is printed?