Java OCA OCP Practice Question 1065

Question

What is wrong with the following program?

class Main {
   String s = "abc";

   public static void main(String[] args) {
      System.out.println(s);
   }

}
  • A. Nothing is wrong with the program.
  • B. main() cannot be declared public because Main is not public.
  • C. Because main() is static, it may not access non-static s without a reference to an instance of Main.
  • D. The main() argument list is incorrect.


C.

Note

The non-static s variable may only be accessed with a reference to a Main object.




PreviousNext

Related