What is the output of the following code?
1: abstract class Printable { 2: public final void print() { System.out.println("Printable print"); } //from w ww .j av a 2 s. c o m 3: public static void main(String[] args) { 4: Printable p = new Square(); 5: p.print(); 6: } 7: } 8: public class Square extends Printable { 9: public void print() { System.out.println("Square print"); } 10:}
E.
The code doesn't compile, so options A and B are incorrect.
The issue with line 9 is that print()
is marked as final in the superclass Printable, which means it cannot be overridden. There are no errors on any other lines, so options C and D are incorrect.