✏️ Explanatory Question

What type of error will occur in the following Java program, and how can it be fixed?

public class Example {
    public static void main(String[] args) {
        System.out.println("Hello, World!")
    }
}

👁 1 Views
📘 Detailed Answer
🟢 Easy
No previous question
No next question
💡

Answer with Explanation

Explanation:

The program will not compile because there is a missing semicolon (;) at the end of the System.out.println("Hello, World!") statement. In Java, every statement must end with a semicolon.

Fixed Code:


public class Example {
    public static void main(String[] args) {
        System.out.println("Hello, World!"); // Fixed by adding a semicolon
    }
}

No previous question
No next question