Why these errors <identifier> expected and ';' expected are occurring in below code?

huangapple go评论70阅读模式
英文:

Why these errors <identifier> expected and ';' expected are occurring in below code?

问题

Code:

class Singleton{
    public String str = "";
    private Singleton() { }
    public static Singleton getSingleInstance() {
        return new Singleton();
    }       
}

Error message:

Main.java:10: error: ';' expected
    public String str = "";
                         ^
Main.java:10: error: <identifier> expected
    public String str = "";
                         ^

Question: Why these errors 1) <identifier> expected and 2) ';' expected are occurring in the code below?

英文:

Code :

class Singleton{
    Public String str=&quot;&quot;;
    Private Singleton()
    {  }
    public static  Singleton getSingleInstance()
    {
        return new Singleton();
    }       
}

Error message:

Main.java:10: error: &#39;;&#39; expected
    Public String str=&quot;&quot;;
                 ^
Main.java:10: error: &lt;identifier&gt; expected
    Public String str=&quot;&quot;;
                 ^

Ques:Why these errors 1) <identifier> expected and 2)';' expected are occurring in below code?

答案1

得分: 1

Java是区分大小写的;关键字是public。不是Public

英文:

Java is case sensitive; the keyword is public. Not Public.

huangapple
  • 本文由 发表于 2020年8月15日 12:05:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/63422479.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定