简体   繁体   English

Java主类

[英]Java main class

Here is my java code这是我的java代码

public class Account {
    private String accName;
    private String accId;
    private int balance;

    Account()
    {
        System.out.println("This is an empty constructor.");
    }

    Account(String name)
    {
        accName = name;
        System.out.println("This is an valued constructor.");
    }


    public class main{

        public Static void main(String[] args)
        {
            Account a1 = new Account("raff");
        }
    }
}

cmd says ' "(identifier)" expected public Static void main(String[] args)' cmd 说 '"(identifier)" expected public Static void main(String[] args)'

I can't get the problem yet......我还是没搞明白问题......

You have several problems there:你有几个问题:

  • public class within public class公开课中的公开课
  • main shouldn't be a class there at all main根本不应该是一个班级
  • "Static", a mispelling of the static keyword “静态”, static关键字的拼写错误

Probably this is how you meant to write that:可能这就是你打算写的:

public class Account {
    private String accName;
    private String accId;
    private int balance;

    Account() {
        System.out.println("This is an empty constructor.");
    }

    Account(String name) {
        accName = name;
        System.out.println("This is an valued constructor.");
    }

    public static void main(String[] args) {
        Account a1 = new Account("raff");
    }
}

static关键字与所有其他 Java 关键字一样,应以小写形式编写:

public static void main(String[] args) {

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

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