当前位置: 技术问答>java相关
新学java,遇到一个构造函数的问题,请教!
来源: 互联网 发布时间:2015-05-29
本文导语: 新学java,练习编程,代码如下 import java.io.*; public class DoubleNumber { public static void main(String[] args) { double N1; double N2; number Number1=new number(); number Number2=new number(3.0,5.0); //此行有错误 N1=Number1.GetNumber1();...
新学java,练习编程,代码如下
import java.io.*;
public class DoubleNumber
{
public static void main(String[] args)
{
double N1;
double N2;
number Number1=new number();
number Number2=new number(3.0,5.0); //此行有错误
N1=Number1.GetNumber1();
N2=Number1.GetNumber2();
System.out.print (N1);
System.out.print ('n');
System.out.println (N2);
N1=Number2.GetNumber1();
N2=Number2.GetNumber2();
System.out.print (N1);
System.out.print ('n');
System.out.println (N2);
}
}
class number
{
public void number(){N1=0.0;N2=0.0;}
public void number(double a,double b){N1=a;N2=b;}
public double GetNumber1()
{
double n1;
n1=N1;
return n1;
}
public double GetNumber2()
{
double n2;
n2=N2;
return n2;
}
private double N1;
private double N2;
}
在第九行出现如下错误F:ICEexerciseclassDoubleNumber.java:9: cannot resolve symbol
symbol : constructor number (double,double)
location: class number
number Number2=new number(3.0,5.0);
^
1 error
未能解决,所以特来请教!
import java.io.*;
public class DoubleNumber
{
public static void main(String[] args)
{
double N1;
double N2;
number Number1=new number();
number Number2=new number(3.0,5.0); //此行有错误
N1=Number1.GetNumber1();
N2=Number1.GetNumber2();
System.out.print (N1);
System.out.print ('n');
System.out.println (N2);
N1=Number2.GetNumber1();
N2=Number2.GetNumber2();
System.out.print (N1);
System.out.print ('n');
System.out.println (N2);
}
}
class number
{
public void number(){N1=0.0;N2=0.0;}
public void number(double a,double b){N1=a;N2=b;}
public double GetNumber1()
{
double n1;
n1=N1;
return n1;
}
public double GetNumber2()
{
double n2;
n2=N2;
return n2;
}
private double N1;
private double N2;
}
在第九行出现如下错误F:ICEexerciseclassDoubleNumber.java:9: cannot resolve symbol
symbol : constructor number (double,double)
location: class number
number Number2=new number(3.0,5.0);
^
1 error
未能解决,所以特来请教!
|
public void number(){N1=0.0;N2=0.0;}
public void number(double a,double b){N1=a;N2=b;}
应该是
public number()
和 public number(double a,double b)
吧
public void number(double a,double b){N1=a;N2=b;}
应该是
public number()
和 public number(double a,double b)
吧
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。