Which statement about the following class is correct?
package shapes;? abstract class Shape { abstract String getDescription(); } class RightShape extends Shape { protected String getDescription() { return "rt"; } // g1 } public abstract class Main extends RightShape { // g2 public String getDescription() { return "irt"; } public static void main(String[] edges) { final Shape shape = new Main(); // g3 System.out.print(shape.getDescription()); } //from ww w .j a v a 2 s . co m }
C.
The code does not compile, so Option D is incorrect.
The Main class is abstract; therefore, it cannot be instantiated on line g3.
Only concrete classes can be instantiated, so the code does not compile.
Option C is the correct answer.
The rest of the lines of code compile without issue.
A concrete class can extend an abstract class, and an abstract class can extend a concrete class.
The override of getDescription()
has a widening access modifier, which is fine per the rules of overriding methods.