简体   繁体   English

这种方法有什么问题?

[英]What's wrong with this method?

I'm new to Java can someone please explain to me what's wrong with this method: 我是Java的新手,有人可以向我解释这种方法有什么问题:

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 ) 这意味着您应该键入classinterface (在您的情况下,应为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. 这意味着,编译器对名为以下类的类一无所知:在这种情况下, 找不到符号意味着什么的Document

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 . 你拼错了class
  2. Where is Document coming from? Document从哪里来?
  3. The formatting is terrible. 格式很糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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