How many lines of the following class do not compile?
1: package mypkg; 2: abstract class Bird { 3: protected int sing; 4: protected abstract int m(); 5: int sing() { 6: return sing; 7: } /*from w w w . j a v a 2s.c o m*/ 8: } 9: public class MyBird extends Bird { 10: int m() { 11: sing() += 10; 12: return super.m()+1; 13: return 10; 14: } 15: }
D.
Line 10 does not compile because the override reduces the visibility of an inherited method, with the package-private modifier being more restrictive than the protected modifier.
Line 11 does also not compile, since the left-hand side of a compound assignment operator must be used with a variable, not a method.
Line 12 does not compile because super.
m()
is inherited as an abstract method in the MyBird
class, meaning the parent class has no implementation.
Option D is the correct answer.