I have a class with four constructors. When I try to compile the main class, I get the error “cannot find symbol” at the last line of this code fragment. But every constructor for this class defines value, so I don’t know what’s going on. What am I missing?
import java.math.BigDecimal;
public class PowerTwo {
public PowerTwo(int n){
final BigDecimal value = new BigDecimal(n);
}
public PowerTwo(long n){
final BigDecimal value = new BigDecimal(n);
}
public PowerTwo(BigDecimal n){
final BigDecimal value = n;
}
public PowerTwo(String n){
final BigDecimal value = new BigDecimal(n);
}
public int power(){
BigDecimal two = new BigDecimal("2");
BigDecimal remainder = value;
You need to make it a field, not a local variable:
It should be outside the constructors.