Что выведет код? 👆
Anonymous Quiz
37%
true true false true
22%
true false false true
37%
false false false true
5%
true false true true
🎉2❤1👍1
public class Test {
public static void main(String[] args) {
System.out.print(testMethod() + " ");
}
static int testMethod() {
try {
throw new RuntimeException("Test exception");
} catch (RuntimeException e) {
System.out.println("Catch ");
return 1;
} finally {
System.out.println("Finally ");
return 2;
}
}
}❤3
Что выведет код? 👆
Anonymous Quiz
10%
Catch Finally 1
64%
Catch Finally 2
16%
Catch 1 Finally
10%
Finally Catch 2
❤1🎉1
interface A {
default void show() {
System.out.println("A");
}
}
interface B {
default void show() {
System.out.println("B");
}
}
abstract class C {
public void show() {
System.out.println("C");
}
}
public class D extends C implements A, B {
public static void main(String[] args) {
new D().show();
}
}❤1👍1🔥1
❤2🎉2👍1
public class Test {
public static void main(String[] args) {
Number[] numbers = new Integer[3];
numbers[0] = 42;
numbers[1] = 3.14;
System.out.println(numbers[0]);
}
}❤1👍1
🎉4
public class Test {
enum Level {
LOW, MEDIUM, HIGH
}
public static void main(String[] args) {
Level level = null;
switch (level) {
case LOW:
System.out.println("Low");
break;
case MEDIUM:
System.out.println("Medium");
break;
case HIGH:
System.out.println("High");
break;
}
}
}❤3
Что выведет код? 👆
Anonymous Quiz
7%
Low
32%
<Ничего>
18%
<Ошибка компиляции>
42%
<NullPointerException>
🤔4🎉1
public class Test {
public static void main(String[] args) {
Shape s = new Circle(5);
switch (s) {
case Circle c -> System.out.println("Circle with r=" + c.radius());
case Rectangle r -> System.out.println("Rectangle: " + r.width() + "x" + r.height());
}
}
sealed interface Shape permits Circle, Rectangle {}
record Circle(int radius) implements Shape {}
record Rectangle(int width, int height) implements Shape {}
}❤1
Что выведет код (Java 21+)? 👆
Anonymous Quiz
53%
Circle with r=5
16%
Rectangle: 0x0
31%
<Ошибка компиляции>
🤯5🎉1
public class Test {
public static void main(String[] args) {
Expr expr = new Add(new Literal(2), new Literal(3));
switch (expr) {
case Add(Literal l1, Literal l2) -> System.out.println("Sum: " + (l1.value() + l2.value()));
case Literal l -> System.out.println("Single literal: " + l.value());
default -> System.out.println("Unknown expression");
}
}
sealed interface Expr permits Literal, Add {}
record Literal(int value) implements Expr {}
record Add(Expr left, Expr right) implements Expr {}
}👍1
Что выведет код (Java 21+)? 👆
Anonymous Quiz
44%
Sum: 5
17%
Single literal: 2
25%
Unknown expression
13%
<Ошибка компиляции>
🎉1
import java.util.HashSet;
import java.util.Set;
class Item {
private String name;
public Item(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Item item = (Item) o;
return name != null ? name.equals(item.name) : item.name == null;
}
}
public class Test {
public static void main(String[] args) {
Set<Item> items = new HashSet<>();
items.add(new Item("apple"));
items.add(new Item("banana"));
items.add(new Item("apple"));
System.out.println(items.size());
}
}
❤2
👍1🎉1
Какой из следующих методов НЕ является методом интерфейса java.util.Collection?
Anonymous Quiz
10%
size()
13%
isEmpty()
22%
get(int index)
22%
contains(Object o)
34%
toArray()
🎉1
import java.util.stream.IntStream;
public class Test {
public static void main(String[] args) {
boolean found = IntStream.range(1, 6)
.peek(x -> System.out.print("P"))
.filter(x -> {
System.out.print("F");
return x % 2 == 0;
})
.anyMatch(x -> {
System.out.print("M");
return x > 2;
});
}
}
👍3
Что выведет код? 👆
Anonymous Quiz
30%
PPPPPFFFFFMMMMM
25%
PPPPPFFFFFMM
33%
PFPFMPFPFM
12%
PFPFMPFPFMPF
🎉1
public class Test {
public static void main(String[] args) {
Parent obj = new Child();
System.out.print(obj.x);
obj.printX();
}
}
class Parent {
public int x = 10;
public void printX() {
System.out.print(" Parent x: " + x);
}
}
class Child extends Parent {
public int x = 20;
@Override
public void printX() {
System.out.print(" Child x: " + x);
}
}❤2👍1
Что выведет код? 👆
Anonymous Quiz
13%
10 Parent x: 10
12%
20 Parent x: 10
32%
10 Child x: 20
43%
20 Child x: 20
❤3🎉1
import java.math.BigInteger;
public class Test {
public static void main(String[] args) {
BigInteger fiveThousand = new BigInteger("5000");
BigInteger fiftyThousand = new BigInteger("50000");
BigInteger fiveHundredThousand = new BigInteger("500000");
BigInteger total = BigInteger.ZERO;
total.add(fiveThousand);
total.add(fiftyThousand);
total.add(fiveHundredThousand);
System.out.println(total);
}
}
❤2