🎉3
public class Test {
public static void main(String[] args) {
Object[] arr = new String[1];
arr[0] = 100;
System.out.println(arr[0]);
}
}❤2
Что выведет код? 👆
Anonymous Quiz
34%
100
17%
<Ошибка компиляции>
27%
<Возникнет ArrayStoreException во время выполнения>
22%
<Возникнет ClassCastException во время выполнения>
🎉2👍1
import java.io.*;
class User implements Serializable {
String name = "Alice";
transient int age = 30;
}
public class Test {
public static void main(String[] args) throws Exception {
User user = new User();
// Сериализация
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("user.ser"))) {
out.writeObject(user);
}
// Десериализация
try (ObjectInputStream in = new ObjectInputStream(new FileInputStream("user.ser"))) {
User deserialized = (User) in.readObject();
System.out.println(deserialized.name + " " + deserialized.age);
}
}
}
❤2
❤1🎉1
public class Test {
int x = getX();
{
x = 2;
}
public Test() {
x = 3;
}
int getX() {
return 1;
}
public static void main(String[] args) {
Test t = new Test();
System.out.println(t.x);
}
}❤1
🎉1
public class Test {
public static void main(String[] args) {
System.out.print(testMethod() + " ");
}
static int testMethod() {
int x = 1;
try {
return x;
} finally {
x++;
System.out.print("In finally: x = " + x + " ");
}
}
}❤1🔥1
Что выведет код? 👆
Anonymous Quiz
28%
In finally: x = 2 1
20%
In finally: x = 2 2
46%
1 In finally: x = 2
6%
2 In finally: x = 2
🎉1
class Animal {
void speak() {
System.out.println("speaks ");
}
}
class Dog extends Animal {
void speak() {
System.out.println("barks ");
}
}
public class Test {
public static void makeSpeak(Animal animal) {
System.out.print("Animal ");
animal.speak();
}
public static void makeSpeak(Dog dog) {
System.out.print("Dog ");
dog.speak();
}
public static void main(String[] args) {
Animal a = new Dog();
makeSpeak(a);
}
}👍3
❤2🎉2
public class Test {
public static void main(String[] args) {
String a = "Java";
String b = "Ja" + "va";
String c = "Ja";
String d = c + "va";
String e = new String("Java");
System.out.println(a == b);
System.out.println(a == d);
System.out.println(a == e);
System.out.println(a.equals(e));
}
}❤1
Что выведет код? 👆
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