class value
{
int x,y;
public void value(int a,int b)
{
x=a;y=b;
}
}
public class sclass
{
public static void main(String args[])
{
value val=new value(3,5);
int t=val.x+val.y;
System.out.println("total="+t);
}
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【sure2003】截止到2008-06-25 22:58:46的历史汇总数据(不包括此帖):
    发帖数:181                发帖分:8636               
    结贴数:180                结贴分:8606               
    未结数:1                  未结分:30                 
    结贴率:99.45 %            结分率:99.65 %            
    值得尊敬
      

  2.   


    class value
    {
        int x,y;
        public value(int a,int b)//构造方法不要写void
        {
            x=a;y=b;
        }
    }
      

  3.   

    恩,构造方法没有返回值...
    public value(int a,int b)
      

  4.   

    恩,构造方法没有返回值
    public value(int a,int b)
      

  5.   


    恩,构造方法没有返回值...
    public value(int a,int b)
    class value
    {
        int x,y;
        public void value(int a,int b)//有返回值,所以不是构造方法,而是一个普通的成员方法。
        {
            x=a;y=b;
        }
    }
    public class sclass
    {
        public static void main(String args[])
        {
        value val=new value(3,5);
        int t=val.x+val.y;
        System.out.println("total="+t);
        }
    }
      

  6.   

    那我的理解构造方法前边的public也可以不要的!!