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

✍️По всем вопросам: @Pascal4eg
Download Telegram
public class Test {
public static void main(String[] args) {
String s = null;
System.out.println(s instanceof String);
}
}
❤2
🎉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
🎉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
Что выведет код? 👆
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