Which is the first line to fail to compile?
class Shape { void use() { } // r1 } class Rectangle extends Shape { private void use() { } // r2 public void bang() { } // r3 }
B.
The Rectangle class is a subclass of the Shape class.
Since the use()
method in Rectangle is intended to override the one in Shape, there are certain rules.
One is that the access modifier must not be more specific.
Option B is correct and r2 is the only line with a compiler error in this code.