For the following code:
1. package abcde; 2. 3. public class Bird { 4. protected static int referenceCount = 0; 5. public Bird() { referenceCount++; } 6. protected void fly() { /* Flap wings, etc. */ } 7. static int getRefCount() { return referenceCount; } 8. }
Which statement is true about class Bird and the following class MyClass?
1. package abcde; 2. /*from ww w . java 2s.c om*/ 3. class MyClass extends abcde.Bird { 4. public void fly() { 5. /* MyClass-specific flight code. */ 6. } 7. public int getRefCount() { 8. return referenceCount; 9. } 10. }
fly()
is protected in the superclass, and classes Bird and MyClass are in the same package. fly()
is protected in the superclass and public in the subclass, and methods may not be overridden to be more public. getRefCount()
is static in the superclass, and static methods may not be overridden to be nonstatic. fly()
is ever called on an instance of class MyClass. getRefCount()
is ever called on an instance of class MyClass. C.
Static methods may not be overridden to be nonstatic.
B is incorrect because it states the case backward: methods can be overridden to be more public, not more private.