-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain
More file actions
37 lines (32 loc) · 1.99 KB
/
Copy pathMain
File metadata and controls
37 lines (32 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Cat cat = new Cat("Пончик", 5, "Рыжий");
System.out.println("Количество полей: " + cat.getClass().getDeclaredFields().length);
for (Field field : cat.getClass().getDeclaredFields()) {
switch (field.getModifiers()) {
case 0 -> System.out.println(("Имя поля: " + field.getName() + ", модификатор доступа: Default"));
case Modifier.PRIVATE ->
System.out.println(("Имя поля: " + field.getName() + ", модификатор доступа: Private"));
case Modifier.PUBLIC ->
System.out.println(("Имя поля: " + field.getName() + ", модификатор доступа: Public"));
case Modifier.FINAL ->
System.out.println(("Имя поля: " + field.getName() + ", модификатор доступа: Final"));
case Modifier.PROTECTED ->
System.out.println(("Имя поля: " + field.getName() + ", модификатор доступа: Protected"));
}
}
System.out.println("\n" + "Количество методов: " + cat.getClass().getDeclaredMethods().length);
for (Method method : cat.getClass().getDeclaredMethods()) {
System.out.println("Имя метода: " + method.getName());
}
System.out.println("\n" + "Количество конструкторов: " + cat.getClass().getDeclaredConstructors().length);
for (Constructor constructor : cat.getClass().getDeclaredConstructors()) {
System.out.println("Параметры конструктора: " + Arrays.toString(constructor.getParameterTypes()));
}
}
}