Multiple choice

Consider the following class file: import java.awt.; import java.io.; package student; class test { void display() { System.out.print(“welcome”); } } What type of error will occur?

  1. The package definition must come first

  2. Class should be private

  3. Method should be without void

  4. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java source files follow a strict ordering rule where the package statement must be the first non-comment line. In the provided code, import statements appear before the package declaration, which will cause a compiler error. To fix this, the package student; line must be moved to the top of the file.