Java OCA OCP Practice Question 1248

Question

Given the following application, what is the expected output?

public class MyClass { 
        private boolean numLock = true; 
        static boolean capLock = false; 
        public static void main(String... shortcuts) { 
           System.out.print(numLock+" "+capLock); 
        } 
} 
  • A. true false
  • B. false false
  • C. It does not compile.
  • D. It compiles but throws an exception at runtime.


C.

Note

The numLock variable is not accessible in the static main() method without an instance of the MyClass class.

The code does not compile.

Option C is the correct answer.




PreviousNext

Related