-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStaticKeyword.java
More file actions
49 lines (38 loc) · 954 Bytes
/
StaticKeyword.java
File metadata and controls
49 lines (38 loc) · 954 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
39
40
41
42
43
44
45
46
47
48
49
import static java.lang.System.out;
class Customer {
static int auto_increment;
int id = 0;
String name;
String dept;
// Static Block
static {
auto_increment = 0;
System.out.println("Static Block Executed...");
}
// Init Block
{
//String dept = "IT";
System.out.println("Init block executed...");
}
// Const Block
public Customer(String name, String dept) {
System.out.println("Const. Called...");
auto_increment++;
this.id = auto_increment;
this.name = name;
this.dept = dept;
}
}
public class StaticKeyword {
public static void main(String[] args) {
Customer obj = new Customer("Ram", "IT");
out.println(obj.id);
out.println(obj.name);
out.println(obj.dept);
Customer obj_2 = new Customer("Shyam", "IT");
System.out.println(obj_2.id);
System.out.println(obj_2.name);
System.out.println(obj_2.dept);
System.out.println(obj.id);
}
}