What happens when two methods are overloaded with array arguments of the type where one is an array of derived type and another is an array of its base type?

  • It depends on the order in which the methods are defined in the class.
  • The compiler throws an error as it cannot distinguish between the two overloaded methods.
  • The method with the array of the base type is called.
  • The method with the array of the derived type is called.
When two methods are overloaded with array arguments in Java, and one takes an array of a derived type while the other takes an array of its base type, the compiler throws an error. This is because the compiler cannot distinguish between the two methods based on the type of the array, as arrays in Java are covariant.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *