简体   繁体   中英

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") ; 
}}

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");
    }
}

You probably meant this:

public class Hello {
    public static void main(String[] args) {
        System.out.println("hello world");
    }
}
  1. You misspelled class .
  2. Where is Document coming from?
  3. The formatting is terrible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM