Question 4
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
class Sensor {
double read() { return 25.0; }
}
class SecureSensor extends Sensor {
@Override
private double read() { return 26.5; }
}
public class Main {
public static void main(String[] args) {
System.out.println(new SecureSensor().read());
}
}
- A read must return float
- B read is package-private in Sensor, and an override cannot narrow it to private Correct
- C SecureSensor must be public
- D private methods cannot return double
Correct Answer: Option B
javac: "attempting to assign weaker access privileges".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!