Skip to content

Commit 507b246

Browse files
authored
bear much fruit
"In this is my Father glorified, that you bear much fruit; and so you will be my disciples. (John 15:8)
1 parent f580b8a commit 507b246

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

‎task15/task1524/Solution.java‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
//"In this is my Father glorified, that you bear much fruit; and so you will be my disciples. (John 15:8)
3+
4+
5+
6+
public class Solution {
7+
static {
8+
init();
9+
}
10+
static {
11+
System.out.println("Static block");
12+
}
13+
14+
{
15+
System.out.println("non-static block");
16+
printAllFields(this);
17+
}
18+
19+
public int i = 6;
20+
21+
public String name = "First name";
22+
23+
24+
public Solution() {
25+
System.out.println("Solution constructor");
26+
printAllFields(this);
27+
}
28+
29+
public static void init() {
30+
System.out.println("static void init()");
31+
}
32+
33+
public static void main(String[] args) {
34+
System.out.println("public static void main");
35+
Solution s = new Solution();
36+
}
37+
38+
public static void printAllFields(Solution obj) {
39+
System.out.println("static void printAllFields");
40+
System.out.println(obj.i);
41+
System.out.println(obj.name);
42+
}
43+
}
44+
45+
46+
47+
48+
/*
49+
Порядок загрузки переменных
50+
Разберись, что и в какой последовательности инициализируется. Поставь брейкпойнты и используй дебаггер.
51+
52+
Исправить порядок инициализации данных так, чтобы результат был следующим:
53+
static void init()
54+
Static block
55+
public static void main
56+
non-static block
57+
static void printAllFields
58+
0
59+
null
60+
Solution constructor
61+
static void printAllFields
62+
6
63+
First name
64+
65+
66+
Требования:
67+
1. Программа должна выводить данные на экран.
68+
2. Вывод на экран должен соответствовать условию задачи.
69+
3. Результатом работы статического инициализатора класса Solution должен быть вывод на экран строк "static void init()" и "Static block".
70+
4. Программа не должна считывать данные с клавиатуры.
71+
72+
73+
package com.javarush.task.task15.task1524;
74+
75+
*
76+
Порядок загрузки переменных
77+
*
78+
79+
public class Solution {
80+
static {
81+
System.out.println("Static block");
82+
}
83+
84+
{
85+
System.out.println("non-static block");
86+
printAllFields(this);
87+
}
88+
89+
public int i = 6;
90+
91+
public String name = "First name";
92+
static {
93+
init();
94+
}
95+
96+
public Solution() {
97+
System.out.println("Solution constructor");
98+
printAllFields(this);
99+
}
100+
101+
public static void init() {
102+
System.out.println("static void init()");
103+
}
104+
105+
public static void main(String[] args) {
106+
System.out.println("public static void main");
107+
Solution s = new Solution();
108+
}
109+
110+
public static void printAllFields(Solution obj) {
111+
System.out.println("static void printAllFields");
112+
System.out.println(obj.name);
113+
System.out.println(obj.i);
114+
}
115+
}
116+
117+
*/

0 commit comments

Comments
 (0)