I'm preparing for a basic certification in Java.
I'm a little confused by the answer to a question that I have got right(!):-
Given:
public class Circle {
static double getCircumference(double radius ) {
return PI * 2 * radius;
}
public static double getArea(double radius) {
return PI * radius * radius;
}
}
Which import statement will enable the code to compile and run?
import java.lang.*;
import static java.lang.Math.PI;
import java.lang.Math.*;
import java.lang.Math;
I answered import static java.lang.Math.PI;
BUT the explanation of two other options below confuses me:-
The statements import java.lang.Math; and import java.lang.Math.*; will not enable the code to compile and run. These import statements will only allow Math.PI as a reference to the PI constant.
My question is: what would be wrong with the import statements only allowing a reference to the PI constant? Would the value be uninitialized and zero?