Java OCA OCP Practice Question 1262

Question

What is the output of the following application?

package mypkg; /*from ww  w  .  j a  va2  s  . co  m*/
class Car { 
   protected final int process() { return 5; } 

} 
public class MyCar extends Car { 
  public final int process() { return 3; } 
  public static void main(String[] chips) { 
     System.out.print(new MyCar().process()); 
  } 
} 
  • A. 5
  • B. 3
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

The process() method is declared final in the Car class.

The MyCar class then attempts to override this method, resulting in a compilation error, making Option C the correct answer.




PreviousNext

Related