I'm trying to use a method from another class called Digits开发者_如何转开发 but referring to it in a class called FourDigits. I've tried to create an instance variable by using the following code:
public class FourDigits
private Digits TwoDigitA;
private Digits TwoDigitB;
/**
* Constructor for objects of class FourDigits
*/
public FourDigits()
{
TwoDigitA = new Digits();
TwoDigitB = new Digits();
setValues();
setIncrement();
getDisplayString();
}
The first class, Digits:
public class Digits
private int value;
private int tooHigh;
private String displayString;
public Digits(int anyNum)
{
value = 0;
tooHigh=anyNum;
displayString = "";
}
Thanks!
ok first, your class doesn't have { brackets.. don't know if this is a copy/paste error but well..
and second your constructor needs a int parameter
TwoDigitA = new Digits();
you don't specify an int here..
TwoDigitA = new Digits(12);
or remove the anyNum from
public Digits(int anyNum)
The Digits constructor requires a parameter. Digits() doesn't exist.
Digits constructor takes an integer in your code... you don't give it any integers when you make the "twodigits" and it doesn't have a constructor with no arguments...
精彩评论