Polymorphism

11.How does the Java compiler determine which overloaded method to call?
  • A. Based on the method name only
  • B. Based on the number and type of parameters passed
  • C. Based on the return type
  • D. Based on whether the method is final

Based on the number and type of parameters passed

Based on the number and type of parameters passed

12.Why can’t static methods be overridden in Java?
  • A. Because static methods are inherited automatically
  • B. Because static methods belong to the class, not an instance
  • C. Because static methods are always private
  • D. Because static methods cannot be called from subclasses

Because static methods belong to the class, not an instance

Because static methods belong to the class, not an instance

13.How does polymorphism improve code maintainability?
  • A. By allowing multiple inheritance in Java
  • B. By enabling a single method to have multiple implementations
  • C. By allowing static methods to be modified at runtime
  • D. By enforcing method hiding in subclasses

By enabling a single method to have multiple implementations

By enabling a single method to have multiple implementations

14.Which of the following is an example of runtime polymorphism in Java?
  • A. A method that takes different numbers of parameters in the same class
  • B. A subclass defining a method with the same signature as the superclass method
  • C. A static method defined with the same name in multiple classes
  • D. A constructor with different parameter lists

A subclass defining a method with the same signature as the superclass method

A subclass defining a method with the same signature as the superclass method