Java OCA OCP Practice Question 89

Question

Which is the correct order of statements for a Java class file?

  • A. import statements, package statement, class declaration
  • B. package statement, class declaration, import statement
  • C. class declaration, import statements, package declaration
  • D. package statement, import statements, class declaration


D.

Note

Java classes are defined in this order: package statement, import statements, class declaration, making Option D the only correct answer.

Not all of these statements are required.

For example, a class may not have a package statement, but if it does, it must come first in the file.




PreviousNext

Related