I am trying to access a private final static double from another class.
Here is the class:
public class coolMath{
private final static double alpha = 5.87;
public coolMath(){
}
public static double calDistance(double x1, double y1, double x2, double y2){
double dist = Math.sqrt(Math.pow((x2-x1), 2) + Math.pow((y2-y1),2));
return dist;
}
}
I need to access the variable alpha in another class. Is this possible? Does something need to happen in the constructor to make it available? Any ideas?
Either make
alphaa public field or provide apublic static double getAlpha()that returns it.If you make the field public, you access it like so
double a = coolMath.alpha.Otherwise,
double a = coolMath.getAlpha();I strongly suggest you go through java modifiers again.