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

✍️По всем вопросам: @Pascal4eg
Download Telegram
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❤1
🎉4
public class Test {
public static void main(String[] args) {
double d = 1 / 3;
System.out.print(d);
}
}
❤1
Что выведет код? 👆
Anonymous Quiz
19%
0.0
74%
0.3333333333333333
6%
3
🎉5🔥2
public class CurrentYear {
public static final CurrentYear INSTANCE = new CurrentYear();
private final int diff;
private static final int CURRENT_YEAR = Calendar.getInstance().get(Calendar.YEAR);

public CurrentYear() {
diff = CURRENT_YEAR - 2025;
}

public int getDiff() {
return this.diff;
}

public static void main(String[] args) {
System.out.println(INSTANCE.getDiff());
}
}
👍2
Что выведет код? 👆
Anonymous Quiz
36%
0
21%
-2025
5%
1
39%
<Ошибка компиляции>
🎉2
package a.b;

public class Ku {
public static void main(String[] args) {
System.out.println(Ku.class.getName().replaceAll(".", "/") + ".class");
}
}
❤4
Что выведет код? 👆
Anonymous Quiz
21%
a.b.Ku.class
54%
a/b/Ku.class
26%
//////.class
🎉3👏1
public class Test {
public static void main(String[] args) {
System.out.println(toBeOrNotToBe());
}

static boolean toBeOrNotToBe() {
try {
return true;
} finally {
return false;
}
}
}
Что выведет код? 👆
Anonymous Quiz
27%
true
41%
false
32%
<Ошибка компиляции>
❤3🎉1
public class Boom {
private Boom internalInstance = new Boom();

public Boom() throws Exception {
throw new Exception("Boom!");
}

public static void main(String[] args) {
try {
Boom b = new Boom();
System.out.println("Surprise");
} catch (Exception e) {
System.out.println("I caught!");
}
}
}
❤2
🎉5❤1👍1
class Point {
private final int x, y;
private final String name;

Point(int x, int y) {
this.x = x;
this.y = y;
name = makeName();
}

protected String makeName() {
return "[" + x + "," + y + "]";
}

public final String toString() {
return name;
}
}

public class ColorPoint extends Point {
private final String color;

ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}

protected String makeName() {
return super.makeName() + ":" + color;
}

public static void main(String[] args) {
System.out.println(new ColorPoint(3, 5, "red"));
}
}
🎉2❤1
class Cache {
private static int sum = 0;

static {
initializeIfNecessary();
}

public static int getSum() {
initializeIfNecessary();
return sum;
}

private static boolean initialized = false;

private static synchronized void initializeIfNecessary() {
if (!initialized) {
for (int i = 0; i < 5; i++)
sum += i;
initialized = true;
}
}
}

public class Client {
public static void main(String[] args) {
System.out.println(Cache.getSum());
}
}
❤2👍1👎1
Что выведет код? 👆
Anonymous Quiz
23%
0
35%
10
17%
20
25%
<Ошибка компиляции>
🎉4
public class ShadesOfGray {
public static void main(String[] args) {
System.out.println(X.Y.Z);
}
}

class X {
static class Y {
static String Z = "BLACK";
}
static C Y = new C();
}

class C {
String Z = "WHITE";
}
❤4
Что выведет код? 👆
Anonymous Quiz
27%
BLACK
25%
WHITE
48%
<Ошибка компиляции>
😢11🎉5
public class Test {
public static void main(String[] args) {
final String pig = "length: 10";
final String dog = "length: " + pig.length();
System.out.println(pig == dog);
}
}
❤1👍1🔥1
Что выведет код? 👆
Anonymous Quiz
29%
true
48%
false
23%
<Ошибка компиляции>
👍4❤3🎉1