To access the DIAMETER
member of the Geodetics
class, we need to understand the different ways to access static members.
Option A) import com.sun.scjp.Geodetics; public class TerraCarta { public double halfway(){ return Geodetics.DIAMETER/2.0; } }
This option is correct because it imports the Geodetics
class and accesses the DIAMETER
member using the syntax Geodetics.DIAMETER
.
Option B) import static com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
This option is incorrect because it tries to import the Geodetics
class using the static
keyword, but it does not specify which member of the class to import. Therefore, the line return DIAMETER/2.0;
will cause a compilation error because DIAMETER
is not recognized.
Option C) import static com.sun.scjp.Geodetics. *; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
This option is correct because it imports all the static members of the Geodetics
class using the *
wildcard. Therefore, the line return DIAMETER/2.0;
will correctly access the DIAMETER
member.
Option D) package com.sun.scjp; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
This option is incorrect because it does not import the Geodetics
class, so the line return DIAMETER/2.0;
will cause a compilation error because DIAMETER
is not recognized.
Therefore, the correct answers are Option A and Option C.