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

✍️По всем вопросам: @Pascal4eg
Download Telegram
import java.lang.annotation.*;

public class Test {
public static void main(String[] args) {
printAnnotation(Child.class);
}

static void printAnnotation(Class<?> clazz) {
if (clazz.isAnnotationPresent(Marker.class)) {
System.out.println("Marker is present");
} else {
System.out.println("Marker is NOT present");
}
}
}

@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Marker {
}

@Marker
class Parent {
}

class Child extends Parent {
}
👍3❤1
public class LambdaTest {
public static void main(String[] args) {
new LambdaTest().run();
}

public void run() {
Runnable r1 = new Runnable() {
@Override
public void run() {
System.out.println("Anonymous: " + this.getClass().getName());
}
};

Runnable r2 = () -> {
System.out.println("Lambda: " + this.getClass().getName());
};

r1.run();
r2.run();
}
}
❤2👍1
public class Main {
public static void main(String[] args) {
int a = 5;
int b = 10;
int result = ++a + b++;
System.out.println(result);
}
}
👍3
Что выведет код? 👆
Anonymous Quiz
11%
15
61%
16
21%
17
8%
<Ошибка компиляции>
🎉3
import java.util.Random;

public class Test {
private static Random rnd = new Random();

public static void main(String[] args) {
StringBuffer word = null;
switch (rnd.nextInt(2)) {
case 1: word = new StringBuffer('P');
case 2: word = new StringBuffer('G');
default: word = new StringBuffer('M');
}
word.append('a');
word.append('i');
word.append('n');
System.out.println(word);
}
}
👍3
Что выведет код? 👆
Anonymous Quiz
10%
Pain
18%
Gain
29%
Main
13%
ain
31%
Pain или Gain
🤔7🎉3👍2
Какой модификатор доступа делает член класса доступным только внутри самого класса?
Anonymous Quiz
1%
public
86%
private
10%
protected
2%
default
🎉1
public class Main {
public static void main(String[] args) {
int[] arr = new int[5];
System.out.println(arr[2]);
}
}
❤2🤬1
👍1🎉1
public class Main {
public static void main(String[] args) {
int[] a = {1, 2, 3};
int[] b = a;
b[0] = 99;
System.out.println(a[0]);
}
}
❤1
Что выведет код? 👆
Anonymous Quiz
37%
1
50%
99
5%
0
9%
<Ошибка компиляции>
❤‍🔥2😨2👍1🎉1
class A {
A() {
System.out.print("A");
}
}

class B extends A {
B() {
System.out.print("B");
}
}

public class Test {
public static void main(String[] args) {
B obj = new B();
}
}
❤2