-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPerson.java
48 lines (36 loc) · 1.05 KB
/
Person.java
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
/**
* Block in java:
* A block is just a collection of java Statments.
* which is bundled in a single code pack with {} braces.
*
* Instance Initialization Blocks :
* In a Java program, operations can be performed on methods, constructors and initialization blocks.
* Instance Initialization Blocks or IIB are used to initialize instance variables.
* IIBs are executed before constructors. They run each time when object of the class is created.
* Initialization blocks are executed whenever the class is initialized
* and before constructors are invoked.
* They are typically placed above the constructors within braces.
*/
package javaBlocks;
public class Person
{
private int x;
//Instance Block 1
{
System.out.println("Exmaple value is "+x);
x=100;
}
//Constructor
public Person()
{
System.out.println("Constructor value is "+x);
}
//Instance Block 2
{
System.out.println("Exmaple value is "+200);
}
public static void main(String[] args)
{
new Person();
}
}