Which statement about the following class is correct?
package mypkg; /* w w w .j ava 2s .co m*/ ? abstract class Shape { private int getEqualSides() {return 0;} } abstract class Rectangle extends Shape { public static int getEqualSides() {return 2;} // x1 } public final class Square extends Rectangle { public int getEqualSides() {return 4;} // x2 public static void main(String[] corners) { final Square myFigure = new Square(); // x3 System.out.print(myFigure.getEqualSides()); } }
B.
The code does not compile, so Option D is incorrect.
The issue here is that the override of getEqualSides()
in Square is invalid.
A static method cannot override a non-static method and vice versa.
For this reason, Option B is the correct answer.