public class Test {
public static void main(String[] args) {
System.out.print(op1() + op2() * op3());
}
private static int op1() {
System.out.print(1);
return 1;
}
private static int op2() {
System.out.print(2);
return 2;
}
private static int op3() {
System.out.print(3);
return 3;
}
}❤3👍2
🎉6❤1🔥1
import java.util.Calendar;
public class Test {
public static final Test INSTANCE = new Test();
private final int yearsAgo;
private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);
private Test() {
yearsAgo = CURRENT_YEAR - 2000;
}
public int yearsAgo() {
return yearsAgo;
}
public static void main(String[] args) {
System.out.println(INSTANCE.yearsAgo());
}
}
❤4👍2
🎉2
public class Test {
public static void main(String[] args) {
String s = null;
System.out.println(s instanceof String);
}
}❤2
Что выведет код? 👆
Anonymous Quiz
33%
true
26%
false
30%
<NullPointerException>
11%
<Ошибка компиляции>
🎉3
public class Test {
public static void greet() {
System.out.println("Hello world!");
}
public static void main(String[] args) {
Test t = null;
t.greet();
}
}❤3👍1
Что выведет код? 👆
Anonymous Quiz
40%
Hello world!
45%
<NullPointerException>
15%
<Ошибка компиляции>
🎉2❤1
class A {
void f(int i) { System.out.println("A"); }
}
class B extends A {
void f(long l) { System.out.println("B"); }
}
public class Test {
public static void main(String[] args) {
A obj = new B();
obj.f(10);
}
}❤2
👍3🔥2❤1
public class Test {
public static void main(String[] args) {
System.out.println("a\".length() + \"b".length());
}
}🔥3❤1
🔥3❤1🎉1
public class Test {
public static synchronized void main(String[] a) throws InterruptedException {
Thread t = new Thread() {
public void run() {
pong();
}
};
t.start();
Thread.sleep(1000);
System.out.print("Ping");
}
static synchronized void pong() {
System.out.print("Pong");
}
}👍2
🎉2
public class Test {
static void m(Object o) {
System.out.println("Object");
}
static void m(String s) {
System.out.println("String");
}
public static void main(String[] args) {
m(null);
}
}❤3
❤3🎉2
import java.util.*;
public class Test {
public static void process(Collection<String> c) {
System.out.println("String Collection");
}
public static void process(Collection<Integer> c) {
System.out.println("Integer Collection");
}
public static void main(String[] args) {
List<String> list = new ArrayList<>();
process(list);
}
}
❤1
Что выведет код? 👆
Anonymous Quiz
49%
String Collection
16%
Integer Collection
25%
<Ошибка компиляции>
9%
<Runtime‑исключение>
🎉1
public class Test {
static class R implements AutoCloseable {
public void work() {
throw new RuntimeException("WORK");
}
@Override
public void close() {
throw new RuntimeException("CLOSE");
}
}
public static void main(String[] args) {
try (R r = new R()) {
r.work();
} catch (Exception e) {
System.out.print(e.getMessage() + " ");
for (Throwable sup : e.getSuppressed()) {
System.out.print(sup.getMessage() + " ");
}
}
}
}❤1
Что выведет код? 👆
Anonymous Quiz
22%
WORK
45%
WORK CLOSE
16%
CLOSE WORK
17%
<Ошибка RuntimeException>
🎉1
class A {
public static void foo() {
System.out.println("A");
}
}
class B extends A {
public void foo() {
System.out.println("B");
}
}
public class Test {
public static void main(String[] args) {
A a = new B();
a.foo();
}
}🔥2❤1