Java OCA OCP Practice Question 3154

Question

Look at the following code and choose the right option for the word <access-modifier>:

// Shape.java// w  w w .  j a v  a2s .co  m
public class Shape {
     protected void display() {
             System.out.println("Display-base");
     }
}

// Circle.java
public class Circle extends Shape {
     <access-modifier> void display(){
             System.out.println("Display-derived");
     }
}
  • A . Only protected can be used.
  • B. Public and protected both can be used.
  • C. Public, protected, and private can be used.
  • D. Only public can be used.


B.

Note

You can provide only a less restrictive or same-access modifier when overriding a method.




PreviousNext

Related