Skip to content

Instantly share code, notes, and snippets.

@vivek-vijayan
Created August 26, 2022 12:18
Show Gist options
  • Save vivek-vijayan/e8e041d83d5b49ed2384ec4fc134305d to your computer and use it in GitHub Desktop.
Save vivek-vijayan/e8e041d83d5b49ed2384ec4fc134305d to your computer and use it in GitHub Desktop.
Precedence checking program in Java
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