So it's possible to call static members on their class without an obj: line 5.2.
But it's OK to call it on an obj too: line 5 (as all objs can access everything inside their class).
line 1 - a constructor is used only when an object is created with the "new" operator
line 2 - a static initialization block runs to initialize the static vars, so after the class and its static vars are created for the first time in memory by the JVM.
lines 4 - the comments are needed bc in a static method you can NOT use non-static vars. The reverse is valid: non-static methods can use static vars bc they exist already since the class was created.
If the app is corrected it will print:
In Test
In X3
In X3
|
Oracle Certified Professional Java Programmer
Author:
JavaChamp TeamSenior Java Developer
QuizOver.com
Germany
Access: |