开发者

Java - cannot find symbol - constructor

开发者 https://www.devze.com 2023-02-20 03:06 出处:网络
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:

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消