Java OCA OCP Practice Question 1480

Question

Which is the first line to fail to compile?

class Shape { 
   void use() { }     // r1 
} 
? 
class Rectangle extends Shape { 
   private void use(String s) { }  // r2 
   public void bang() { }  // r3 
} 
  • A. r1
  • B. r2
  • C. r3
  • D. None of the above


D.

Note

The Rectangle class is a subclass of the Shape class.

The use() method has a different signature so it is not an override.

It is fine that the access modifier is stricter, and Option D is correct.

Line r3 is a valid method unrelated to the superclass.




PreviousNext

Related