Given:
package com.sun.ocjp;
public class Geodetics {
public static final double DIAMETER = 12756.32; // kilometers
}
Which two correctly access the DIAMETER member of the Geodetics class?
A. import com.sun.ocjp.Geodetics;
public class TerraCarta {
public double halfway(){ return Geodetics.DIAMETER/2.0; }
B. import static com.sun.ocjp.Geodetics;
public class TerraCarta{
public double halfway() { return DIAMETER/2.0; } }
C. import static com.sun.ocjp.Geodetics.*;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
D. package com.sun.ocjp;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
Execution:
The option C will import all Static data and members, so it can be access variable directly.
The option A will access static variable using class name
The option B/D does not have access to static variable as Static import in B will not able to access class internal statics and D does not use object or class name for accessing.
Answer: A,C
A. import com.sun.ocjp.Geodetics;
public class TerraCarta {
public double halfway()
{ return Geodetics.DIAMETER/2.0; }
C. import static com.sun.ocjp.Geodetics.*;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
package com.sun.ocjp;
public class Geodetics {
public static final double DIAMETER = 12756.32; // kilometers
}
Which two correctly access the DIAMETER member of the Geodetics class?
A. import com.sun.ocjp.Geodetics;
public class TerraCarta {
public double halfway(){ return Geodetics.DIAMETER/2.0; }
B. import static com.sun.ocjp.Geodetics;
public class TerraCarta{
public double halfway() { return DIAMETER/2.0; } }
C. import static com.sun.ocjp.Geodetics.*;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
D. package com.sun.ocjp;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
Execution:
The option C will import all Static data and members, so it can be access variable directly.
The option A will access static variable using class name
The option B/D does not have access to static variable as Static import in B will not able to access class internal statics and D does not use object or class name for accessing.
Answer: A,C
A. import com.sun.ocjp.Geodetics;
public class TerraCarta {
public double halfway()
{ return Geodetics.DIAMETER/2.0; }
C. import static com.sun.ocjp.Geodetics.*;
public class TerraCarta {
public double halfway() { return DIAMETER/2.0; } }
No comments:
Post a Comment