❤7👎4🤡4🎉2
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
🎉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
🎉2
package a.b;
public class Ku {
public static void main(String[] args) {
System.out.println(Ku.class.getName().replaceAll(".", "/") + ".class");
}
}
❤4
🎉3👏1
public class Test {
public static void main(String[] args) {
System.out.println(toBeOrNotToBe());
}
static boolean toBeOrNotToBe() {
try {
return true;
} finally {
return false;
}
}
}❤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
Что выведет код? 👆
Anonymous Quiz
22%
Boom!
20%
Surprise
34%
I caught!
24%
<Ошибка StackOverflowError>
🎉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
🎉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
😢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