Sorry, just learning Java; but, can someone tell me why I’m getting a “cannot find symbol” error?
My code is as follows:
public class NumberHolder {
public int anInt;
public float aFloat;
public NumberHolder(int setAnInt, float setAFloat) {
setAnInt = anInt;
setAFloat = aFloat;
}
public static void main(String[] args) {
NumberHolder newNumber = NumberHolder(12, 24F);
}
}
Looks like you’re missing a
newbefore the call to the constructor:EDIT:
Also, as Tassos Bassoukos points out in his answer, you need to turn around the assignments in the constructor:
Although personally, I like to write my constructors like this:
This is a matter of style and personal preference, though.