Created
August 26, 2022 12:18
-
-
Save vivek-vijayan/e8e041d83d5b49ed2384ec4fc134305d to your computer and use it in GitHub Desktop.
Precedence checking program in Java
This file contains hidden or 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 Test { | |
// Empty scope - equvalent to normal variable initialisation - P2 | |
{ | |
System.out.println("Empty scope called"); | |
} | |
// constructor - P3 | |
Test() { | |
System.out.println("Constructor called"); | |
} | |
// Static scope - equivalent to static variable initialisation - P2 | |
static { | |
System.out.println("Static scope 1 called"); | |
} | |
static { | |
System.out.println("Static scope 2 called"); | |
} | |
} | |
public class PrecedenceCheck { | |
public static void main(String[] args) { | |
new Test(); | |
} | |
} | |
/* | |
* Output: | |
* Static scope 1 called | |
* Static scope 2 called | |
* Empty scope called | |
* Constructor called | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment