What is the output of the following code?
1: public abstract class Shape { 2: public abstract void draw() {}; 3: public static void main(String[] args) { 4: Shape s = new Rectangle(); 5: s.draw(); 6: } 7: } 8: class Rectangle extends Shape { 9: public void draw(int depth) { System.out.println("Rectangle draw"); } 10: }
B.
Line 2 contains an invalid definition of an abstract method.
Abstract methods cannot contain a body, so the code will not compile and B is the correct answer.