Skip to content

Instantly share code, notes, and snippets.

@anjanashankar9
Last active November 15, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anjanashankar9/181f403bd9d875459e10c785dae552b8 to your computer and use it in GitHub Desktop.
Save anjanashankar9/181f403bd9d875459e10c785dae552b8 to your computer and use it in GitHub Desktop.
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