RT..
class WaterSource
{
private String s;
WaterSoure()
{
System.out.println("WaterSource()");
s = new String("Constructed");
}
public String toString() { return s; }
}
class Art
{
Art()
{
System.out.println("Art constructor");
}
}上面二段代码.第一段WaterSource类编译时会出错,提示需要返回类型.
但第二段代码Art类编译时就没有这个问题.请问这是什么原因呢.?谢谢.

解决方案 »

  1.   

    WaterSoure->WaterSource
    ps:
    s = new String("Constructed");-> s = "Constructed";
      

  2.   

    Art()
    {
      System.out.println("Art constructor");
    }请问像这样前面没有指明返回类型的是表示没有返回值吗? 那为什么不声明成void呢.?
      

  3.   

    构造方法一定要用 CTRL - V 的方法来写,万无一失
      

  4.   

    class WaterSource
    {
    private String s;
    WaterSource()
    {
    System.out.println("WaterSource()");
    s = new String("Constructed");
    }
    public String toString() { return s; }
    }
      

  5.   

    一楼的老兄给你指出了错误指出,
    另外给你提了一个意见,把s = new String("Constructed");改成s = "Constructed"
    因为前者肯定会申请空间,后者则不一定了,所以后者的写法比前者的好