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
👍4❤3🎉1
public class Counter {
public static void main(String[] args) {
int counter = 0;
counter = counter++;
System.out.println(counter);
}
}❤3⚡2
🎉4
public class Test {
public static void main(String[] args) {
System.out.println(calc());
}
static int calc() {
try {
if (1 == 1)
throw new RuntimeException();
return 1;
} catch (Exception e) {
return 2;
} finally {
return 3;
}
}
}👍7❤1
🎉5
import java.util.List;
public class Test {
public static void main (String[] args) {
print(List.of(1, 2, 3));
}
private static void print(List<String> list) {
System.out.println(1);
}
private static void print(List<Integer> list) {
System.out.println(2);
}
}
❤1
🎉3