-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDemoStatic.java
More file actions
38 lines (27 loc) · 799 Bytes
/
DemoStatic.java
File metadata and controls
38 lines (27 loc) · 799 Bytes
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
package StaticTrongJava;
public class DemoStatic {
//Khối static
//Chạy trước hàm main
static {
System.out.println("Khối static: hello !");
}
static String name = "Ánh";
static int age = 30;
String address = "Hồ Chí Minh";
public static void getInfo(){
System.out.println(name);
System.out.println(age);
DemoStatic demoStatic = new DemoStatic();
System.out.println(demoStatic.address);
}
public String getAddress(){
System.out.println(name);
return address;
}
public static void main(String[] args) {
DemoStatic demoStatic = new DemoStatic();
System.out.println(demoStatic.address);
demoStatic.getAddress();
DemoStatic.getInfo();
}
}