-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathConstructorDemo.java
More file actions
46 lines (36 loc) · 926 Bytes
/
ConstructorDemo.java
File metadata and controls
46 lines (36 loc) · 926 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
class Customer {
static int x;
int y;
// static block
static {
//x = 10;
// cannot initialize non-static variables
//y = 12;
System.out.println("Static block executed...");
}
// Init Block - will be executed when object of class is created
// but before constructor call
// {
// System.out.println("This is also a block...");
// }
public Customer() {
this(10);
System.out.println("Object Created...");
}
public Customer(int x) {
//this(); // will call default constructor...
System.out.println("Object Created inside parameterized const...");
}
// Init Block
{
//x = 12;
y = 12;
System.out.println("This is also a block...");
}
}
public class ConstructorDemo {
public static void main(String[] args) {
Customer obj_1 = new Customer(); // calls default const
//Customer obj_2 = new Customer(10); // calls param const
}
}