我正在学习Java并遇到了这个问题。问题陈述在这里不是很重要。运行代码时出现错误。代码是
class constructor1
{
Public static void main(String args[])
{
Example1 obj1 = new Example1(20,30);
Example1 obj2 = new Example1(10,20);
obj1.show();
obj2.show();
}
}
class Example1
{
int a,b;
Example1(int x,int y)
{
a = x;
b = y;
}
void show()
{
system.out.println("a = " + a + "b =" + b);
}
}
错误是
constructor1.java:3: error: <identifier> expected
Public static void main(String args[])
^
1 error
我搜索了许多在线资源以纠正错误,但找不到它。有人可以帮忙该错误的原因是什么?
答案 0 :(得分:1)
public
是关键字,大小写很重要。
您编写了Public
,编译器无法将其理解为关键字,但认为您可能正在引用名为Public
的类型,因此正在等待变量名(因此需要“标识符”)。
将Public
更改为public
。