-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
112 lines (89 loc) · 3.2 KB
/
Solution.java
File metadata and controls
112 lines (89 loc) · 3.2 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//They cried out, "Away with him! Away with him! Crucify him!" Pilate said to them, "Shall I crucify your King?" The chief priests answered, "We have no king but Caesar!" (John 19:15)
package com.javarush.task.task20.task2023;
/*
Делаем правильный вывод
*/
public class Solution {
public static void main(String[] s) {
A a = new C();
a.method2();
}
public static class A {
private void method1() {
System.out.println("A class, method1");
}
public void method2() {
System.out.println("A class, method2");
method1();
}
}
public static class B extends A {
public void method1() {
super.method2();
System.out.println("B class, method1");
}
public void method2() {
System.out.println("B class, method2");
}
}
private static class C extends B {
public void method1() {
System.out.println("C class, method1");
}
public void method2() {
System.out.println("C class, method2");
super.method1();
}
}
}
/*
Делаем правильный вывод
Расставить обращение к методам суперкласса и модификаторы доступа так, чтобы вывод на экран был следующим:
C class, method2
A class, method2
A class, method1
B class, method1
1. Из одного метода можно вызвать только один метод суперкласса.
2. Из одного метода можно вызвать только один метод класса.
3. Можно менять модификаторы доступа к методам.
Требования:
1. Вывод на экран должен соответствовать условию задачи.
2. Метод method1 должен быть объявлен с модификатором доступа private в классе A.
3. Метод method1 в классе B должен содержать вызов super.method2().
4. Метод method2 в классе С должен содержать вызов super.method1().
5. Метод method2 в классе A должен содержать вызов method1().
package com.javarush.task.task20.task2023;
*
Делаем правильный вывод
*
public class Solution {
public static void main(String[] s) {
A a = new C();
a.method2();
}
public static class A {
public void method1() {
System.out.println("A class, method1");
}
public void method2() {
System.out.println("A class, method2");
}
}
public static class B extends A {
public void method1() {
System.out.println("B class, method1");
}
public void method2() {
System.out.println("B class, method2");
}
}
public static class C extends B {
public void method1() {
System.out.println("C class, method1");
}
public void method2() {
System.out.println("C class, method2");
}
}
}
*/