John
John

Reputation: 17

What's wrong with this method?

I'm new to Java can someone please explain to me what's wrong with this method:

clas Hello {
public static void main (String[]arg) {
Document.write ("hello world") ; 
}}

Upvotes: 0

Views: 157

Answers (3)

OscarRyz
OscarRyz

Reputation: 199234

This is the compiler output:

Hello.java:1: 'class' or 'interface' expected
clas Hello {
^
1 error

That means, that you should either type class or interface ( In your case it should be class )

Assuming you had an error while copy/pasting it here, the problem reported by the compiler is:

Hello.java:3: cannot find symbol
symbol  : variable Document
location: class Hello
        Document.write ("hello world") ; 
        ^
1 error

That means, the compiler doesn't know anything about a class named: Document that's what cannot find symbol means in this case.

Perhaps you want to write:

 System.out.println("Hello world");

Complete running program:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello world");
    }
}

Upvotes: 14

Yishai
Yishai

Reputation: 91881

You probably meant this:

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

Upvotes: 5

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798744

  1. You misspelled class.
  2. Where is Document coming from?
  3. The formatting is terrible.

Upvotes: 3

Related Questions