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.)
A. import com.sun.scjp.Geodetics;
public class TerraCarta{
public double halfway()
{return Geodetics.DIAMETER/2.0;}
B. import static com.sun.scjp.Geodetics;
public class TerraCarta{
public double halfway(){return DIAMETER/2.0;}}
C import static com.sun.scjp.Geodetics.*;
public class TerraCarta{
public double halfway(){return DIAMETER/2.0;}}
D. package com.sun.scjp;
public class TerraCarta{
public double halfway(){return DIAMETER/2.0;}}
答案:AC
參考:8-2 方法種類與呼叫方式
------------------------------------------------
DIAMETER 是 static 變數, 存取他要透過類別名稱.
A.
C. 直接import static
沒有留言:
張貼留言