菜鸟求教一个关于构造函数的问题,编译发生错误,哭~~~~~
代码如下:
class person
{
public person()
{
System.out.println( "Name initial ");
}
private int age=10;
public void shout()
(
System.out.println( "age is " + age);
)
}
class testgouzao
{
public static void main(String[] args)
{
person p1=new person();
p1.shout();
person p2=new person();
p2.shout();
person p3=new person();
p3.shout();
}
}
奇怪的是编译时说 testgouzao.java:9: "; " expected
可是我怎么找都没有漏 "; "号啊?希望大家能帮我看下,谢谢
------解决方案--------------------来一个
------解决方案--------------------class person
{
public person()
{
System.out.println( "Name initial ");
}
private int age=10;
public void shout()
{
System.out.println( "age is " + age);
}
}
class testgouzao
{
public static void main(String[] args)
{
person p1=new person();
p1.shout();
person p2=new person();
p2.shout();
person p3=new person();
p3.shout();
}
}
------解决方案--------------------public void shout()
(
System.out.println( "age is " + age);
) 老大 是大括号啊。