Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instance Initialization
class InitializerTest {
int i;
{
System.out.println("Instance Initialization block is called");
i = 5;
}
InitializerTest() {
System.out.println("Initializer Test Default Constructor is called");
}
InitializerTest(int x) {
System.out.println("Initializer Test Parametrized Constructor is called");
i = x;
}
}
class Main {
public static void main (String args[]){
InitializerTest obj1 = new InitializerTest();
System.out.println(obj1.i);
InitializerTest obj2 = new InitializerTest(10);;
System.out.println(obj2.i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment