Java OCA OCP Practice Question 498

Question

Given the following code, which combination of access modifiers

  • public
  • protected
  • private

can legally be placed before aMethod() on line 3 and be placed before aMethod() on line 8?

1. class SuperDuper 
2. { 
3.     void aMethod() { } 
4. } 
5. 
6. class Sub extends SuperDuper 
7. { 
8.     void aMethod() { } 
9. } 
  • A. line 3: public; line 8: private
  • B. line 3: protected; line 8: private
  • C. line 3: default; line 8: private
  • D. line 3: private; line 8: protected
  • E. line 3: public; line 8: protected


D.

Note

A method may not be overridden to be more private.

All choices except D make the access of the overriding method more private.




PreviousNext

Related