go to previous page   go to home page   go to next page hear noise highlighting

Answer:

The first letter of "Class" is wrong.


A Capital Mistake

The reserved word "class" has been changed to "Class" with a capital "C". So what? This is called a syntax error. A syntax error is a "grammatical error" in using the programming language. Here is what happens when the mistaken program is compiled:

The compiler tried to translate the source code into bytecode but got confused when it got to a capital "C" it did not expect. The error message is not very clear. They never are. But at least it shows where the compiler got confused. The compiler did not create a new bytecode file because it stopped translating when it got to the error.


C:\JavaSource>javac Hello.java

  compiling: Hello.java
Hello.java:1: Class or interface declaration expected.
public Class Hello
       ^
1 error

QUESTION 8:

What is the error in the following program?

public class hello
{
  public static void main ( string[] args )
  {
    System.out.println("hello world!");
  }
}

Click for a hint.


go to previous page   go to home page   go to next page