import java.util.ArrayList;
import java.util.List;
public class Test {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(10);
list.add(20);
list.add(30);
list.remove(1);
list.remove(Integer.valueOf(30));
System.out.println(list);
}
}
❤1
❤6🎉2
public class Counter {
public static void main(String[] args) {
int counter = 0;
counter = counter++;
System.out.println(counter);
}
}❤2
🤔5🥱2❤1🎉1
public class Test {
public static void main(String[] args) {
Object o1 = (true) ? new Integer(10) : new Double(20.0);
System.out.println(o1);
}
}❤3🫡1
Что выведет код? 👆
Anonymous Quiz
37%
10
15%
10.0
10%
20.0
24%
<Ошибка компиляции (несовместимые типы)>
15%
<ClassCastException>
😁4❤2🎉2
public class Test {
public static void main(String[] args) {
// Сравнение нулей
double d1 = 0.0;
double d2 = -0.0;
System.out.print((d1 == d2) + " ");
System.out.print(Double.valueOf(d1).equals(Double.valueOf(d2)) + " ");
// Сравнение NaN (Not a Number)
double n1 = Double.NaN;
double n2 = Double.NaN;
System.out.print((n1 == n2) + " ");
System.out.print(Double.valueOf(n1).equals(Double.valueOf(n2)));
}
}🔥3❤1
Что выведет код? 👆
Anonymous Quiz
16%
true true true true
27%
true false false true
19%
true true false false
30%
false true true false
8%
true false false false
🔥4🎉1
import java.io.*;
class Data implements Serializable {
int x = 10;
static int y = 20;
transient int z = 30;
}
public class Test {
public static void main(String[] args) throws Exception {
Data d = new Data();
// 1. Сериализация (сохраняем объект в байты)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(d);
// 2. Изменяем статическое поле ПОСЛЕ сериализации
Data.y = 50;
// 3. Десериализация (восстанавливаем объект из байтов)
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
Data dRestored = (Data) ois.readObject();
System.out.println(dRestored.x + " " + dRestored.y + " " + dRestored.z);
}
}
👍2❤1
👍3🎉1
public class Test {
public static void main(String[] args) {
String[] strings = {"Java", "Code"};
Object[] objects = strings; // 1
System.out.print(objects[0] + " ");
try {
objects[1] = 100; // 2
System.out.print("Success");
} catch (Exception e) {
System.out.print(e.getClass().getSimpleName());
}
}
}❤3
Что выведет код? 👆
Anonymous Quiz
26%
Java Success
33%
Java ClassCastException
18%
Java ArrayStoreException
10%
<Ошибка компиляции на строке 1>
13%
<Ошибка компиляции на строке 2>
🎉5👍1
interface I {
static void print() {
System.out.print("I-static ");
}
}
class C implements I {
public static void print() {
System.out.print("C-static ");
}
}
public class Test {
public static void main(String[] args) {
C c = new C();
I i = c;
// Строка 1
c.print();
// Строка 2
I.print();
// Строка 3
i.print();
}
}❤1
class Cat {
public static void mew() {
System.out.print("Meow");
}
}
class SimonsCat extends Cat {
public static void mew() { }
}
public class Mew {
public static void main(String[] args) {
Cat cat = new Cat();
Cat simonsCat = new SimonsCat();
cat.mew();
simonsCat.mew();
}
}👍3❤2
👍3🎉1
public class Test {
public static void main(String[] args) {
int x = 0;
int y = 0;
boolean b1 = (x++ > 0) && (y++ > 0);
System.out.print("x=" + x + " y=" + y + ", ");
x = 0;
y = 0;
boolean b2 = (x++ > 0) & (y++ > 0);
System.out.print("x=" + x + " y=" + y);
}
}❤2🔥1
Что выведет код? 👆
Anonymous Quiz
39%
x=1 y=1, x=1 y=1
26%
x=1 y=0, x=1 y=1
8%
x=1 y=0, x=1 y=0
4%
x=2 y=2, x=2 y=2
23%
x=0 y=0, x=1 y=1
❤2👍1🔥1🎉1
Можно ли переопределить (override) private метод в Java?
Anonymous Quiz
14%
Да
62%
Нет
15%
Только в том же пакете
10%
Да, если снять final
❤2🎉2