-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatic.java
More file actions
81 lines (55 loc) · 1.25 KB
/
Static.java
File metadata and controls
81 lines (55 loc) · 1.25 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
// // program for static variable:-
// import java.util.*;
// class Static {
// public static void main(String[] args){
// Test t1 = new Test();
// Test t2 = new Test();
// t2.display();
// t1.display();
// Test t3 = new Test();
// t2.display();
// t1.display();
// t3.display();
// }
// }
// class Test {
// static int counter = 0;
// public Test(){
// counter++;
// }
// public void display(){
// System.out.println(counter);
// }
// }
// Static methods:-
class Static{
public static void main(String[] args) {
// Sample.msg();
Sample s = new Sample();
Sample.Innerclass in = new Sample.Innerclass();
}
}
class Sample{
static class Innerclass {
public Innerclass(){
System.out.println("Innerclass Constructor!");
}
}
static {
System.out.println("Static Block is called!");
}
public Sample(){
System.out.println("Sample Constructor is called!");
}
static int a = 10;
public static void msg(){
System.out.println("HI");
System.out.println(a);
a++;
}
}
// This is not valid!: -
/*
static class Sample2 {
}
*/