Java OCA OCP Practice Question 2349

Question

The following numbered list of Java class components is not in any particular order.

Select the acceptable order of their occurrence in any Java class (choose all that apply):.

1   comments 
2   import statement 
3   package statement 
4   methods 
5   class declaration 
6   variables 
  • a 1, 3, 2, 5, 6, 4
  • b 3, 1, 2, 5, 4, 6
  • c 3, 2, 1, 4, 5, 6
  • d 3, 2, 1, 5, 6, 4


a, b, d

Note

The comments can appear anywhere in a class.

They can appear before and after package and import statements.

They can appear before or after a class, method, or variable declaration.

The first statement (if present) in a class should be a package statement.

It can't be placed after an import statement or a declaration of a class.

The import statement should follow a package statement and be followed by a class declaration.

The class declaration follows the import statements, if present.

It's followed by the declaration of the methods and variables.

Answer c is incorrect.

None of the variables or methods can be defined before the definition of a class or interface.




PreviousNext

Related