Что выведет код?
#Tasks
public class Task210725 {
static int x = 5;
static {
x = 10;
}
public static void main(String[] args) {
System.out.println(x);
int x = 20;
System.out.println(x);
System.out.println(Task210725.x);
}
}
#Tasks
👍2
Что выведет код?
#Tasks
public class Task220725 {
public static void main(String[] args) {
final int x;
try {
x = 10;
throw new RuntimeException();
} catch (Exception e) {
System.out.print(x + " ");
} finally {
x = 20;
System.out.print(x);
}
}
}
#Tasks
👍4
Что выведет код?
#Tasks
public class Task230725 {
private static volatile boolean flag = true;
public static void main(String[] args) {
new Thread(() -> {
while (flag) {
// empty loop
}
System.out.println("Thread stopped");
}).start();
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
flag = false;
System.out.println("Main stopped");
}
}
#Tasks
👍2
Что выведет код?
#Tasks
public class Task240725 {
private static synchronized void print(String msg) {
System.out.print(msg + " ");
}
public static void main(String[] args) {
Thread t1 = new Thread(() -> print("Hello"));
Thread t2 = new Thread(() -> print("World"));
t1.start();
t2.run();
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
#Tasks
👍2