-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasses002.java
More file actions
48 lines (34 loc) · 1.45 KB
/
Copy pathClasses002.java
File metadata and controls
48 lines (34 loc) · 1.45 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
package classesIntro;
/**
* Created by WERT on 13.01.2017.
*/
import static util.Print.printLine;
public class Classes002 {
static Box fieldBox; // поле класса (статическое)
public static void main(String[] args) {
// подробный пример создания экземпляра класса
System.out.println("fieldBox = " + fieldBox);
Box mybox; // объявление ссылки на объект
// println("mybox = " + mybox); // ошибка компиляции
mybox = null;
System.out.println("mybox = " + mybox);
mybox = new Box(); // создание в памяти экземпляра объекта Box
System.out.println("mybox = " + mybox);
System.out.println("mybox.height = " + mybox.height);
printLine();
System.out.println();
Box b1 = new Box();
b1.label = "box1";
System.out.println("box1.label = " + b1.label);
Box b2 = b1; // b1 и b2 ссылаются на один объект
b2.label = "box2";
System.out.println("box1.label = " + b1.label);
b2 = new Box(); // теперь b2 ссылается на другой объект
b1.label = "box1";
b2.label = "box2";
printLine();
System.out.println();
System.out.println("box1.label = " + b1.label);
System.out.println("box2.label = " + b2.label);
}
}