Given: 10. package com.sun.scjp; 11. public class Geodetics { 12. public static final double DIAMETER = 12756.32; // kilometers 13. } Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.)

  1. import com.sun.scjp.Geodetics;public class TerraCarta {public double halfway(){ return Geodetics.DIAMETER/2.0; } }

  2. import static com.sun.scjp.Geodetics;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }

  3. import static com.sun.scjp.Geodetics. *;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }

  4. package com.sun.scjp;public class TerraCarta {public double halfway() { return DIAMETER/2.0; } }


Correct Option: A,C

AI Explanation

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.

Find more quizzes: