Java OCA OCP Practice Question 1310

Question

To compile the public class MyClass successfully, which of the following are true?

  • A. MyClass must have a correctly formed main() method.
  • B. MyClass must be defined in the file MyClass.java.
  • C. MyClass must be defined in the MyClass package.
  • D. MyClass must be imported.


B.

Note

A class does not need a main() method to compile.

Nor does it need to be defined in a package or imported.

However, a public class needs to be defined in a source code file of the same name.




PreviousNext

Related