OCA Java SE 8 Mock Exam 2 - OCA Mock Question 33








Question

Given the following code, which of the options are true?

         class Shape { 
             void print() {} 
         } 
         class Rectangle extends Shape { 
             void print() {} 
         } 
         class Square extends Shape { 
             void print() {} 
         } 
  1. The method print defined in the classes Shape, Rectangle, and Square is polymorphic.
  2. Only the method print defined in the classes Shape and Square is polymorphic.
  3. Only the method print defined in the class Square is polymorphic.
  4. None of the above.




Answer



A

Note

When methods with the same method signature are defined in classes that share an inheritance relationship, the methods are considered polymorphic.