Java OCA OCP Practice Question 2613

Question

Given:

2. class Shape {  
3.   void m(int x) { }  
4. }  /*from  w w w .ja va 2 s  .co m*/
5. class Rectangle extends Shape {  
6.   // void m(byte b) { }  
7.   // protected void m(int x) throws Exception { }  
8. }   
9. public class Square extends Rectangle {  
10.   // void m(int x) { }   
11.   // String m(int x) { return "hi"; }  
12.   // public int m(int x) { return 7; }   
13.   // private int m(char c) throws Error { return 1; }   
14. } 

Which method(s), if uncommented independently, compile? (Choose all that apply.)

  • A. Line 6
  • B. Line 7
  • C. Line 10
  • D. Line 11
  • E. Line 12
  • F. Line 13


A, C, and F are correct.

Note

A and F are valid overloads of Shape.m(), and C is a valid override of Shape.m().

B, D, and E are all illegal overrides of Shape.m().




PreviousNext

Related