Last active
November 15, 2021 17:12
-
-
Save anjanashankar9/181f403bd9d875459e10c785dae552b8 to your computer and use it in GitHub Desktop.
Instance Initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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