Java OCA OCP Practice Question 100

Question

What is required to define a valid Java class file?

  • A. A class declaration
  • B. A package statement
  • C. At least one import statement
  • D. The public modifier


A.

Note

Option A is the correct answer.

A class definition is the only required component in a Java class file.

Java also allows interfaces and enums to be defined in a file.

A package statement and import statements are optional for declaring a class, making Options B and C incorrect.

A class may be defined with package-level access in a file, making Option D an incorrect answer.




PreviousNext

Related