Java | Tests
1.82K subscribers
1 photo
1 link
Проверь свои знания в Java

✍️По всем вопросам: @Pascal4eg
Download Telegram
public class Test {
public static void main(String[] args) {
System.out.println("a\".length() + \"b".length());
}
}
🔥3❤1
Что выведет код? 👆
Anonymous Quiz
14%
2
26%
16
11%
18
49%
<Ошибка компиляции>
🔥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
Что выведет код? 👆
Anonymous Quiz
37%
PingPong
44%
PongPing
9%
Ping
10%
<Ошибка компиляции>
🎉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
Что выведет код? 👆
Anonymous Quiz
40%
Object
24%
String
36%
<Ошибка компиляции>
❤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
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
🎉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
👍2🎉2
interface A {
default void f() {
System.out.println("A");
}
}

interface B {
default void f() {
System.out.println("B");
}
}

class C implements A, B {

}

public class Test {
public static void main(String[] args) {
new C().f();
}
}
❤3
🎉2❤1
public class Test {
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(() -> System.out.print("X"));

t.run();
t.start();
t.join();

System.out.print("Y");
}
}
👍2❤1
Что выведет код? 👆
Anonymous Quiz
39%
XY
47%
XXY
6%
XYY
8%
XYX
🎉3
public class Test {
static int x = 0;

public static void main(String[] args) throws InterruptedException {
Thread t = new Thread(() -> x = 5);
t.start();
x = 3;
t.join();
System.out.println(x);
}
}
❤3👍2
Что выведет код? 👆
Anonymous Quiz
18%
5
38%
3
44%
3 или 5 (недетерминированно)
🎉5👍1
public class Test {
static void m(Integer i) { System.out.println("Integer"); }
static void m(long l) { System.out.println("long"); }
static void m(int... i) { System.out.println("varargs"); }
static void m(Object o) { System.out.println("Object"); }

public static void main(String[] args) {
m(5);
}
}
❤2👍1
Что выведет код? 👆
Anonymous Quiz
42%
Integer
15%
long
21%
varargs
21%
Object
🎉3
public class Test {
public static void main(String[] args) {
Object[] arr = new String[1];
arr[0] = 100;
System.out.println(arr[0]);
}
}
❤2