Polymorphism

1.Why is method overloading considered compile-time polymorphism?
  • A. Because method resolution happens at runtime
  • B. Because method resolution is done during compilation based on parameter types
  • C. Because method overloading can be done only in abstract classes
  • D. Because overloaded methods must have the same method signature

Because method resolution is done during compilation based on parameter types

Because method resolution is done during compilation based on parameter types

2.In Java, what happens if two overloaded methods have the same parameter types but different return types?
  • A. The compiler treats them as the same method, causing an error
  • B. The compiler automatically selects the method with the most suitable return type
  • C. The program compiles but executes the first method found
  • D. The runtime environment selects the correct method

The compiler treats them as the same method, causing an error

The compiler treats them as the same method, causing an error

3.How does Java decide which overridden method to call at runtime?
  • A. Based on the reference type of the object
  • B. Based on the object type of the instance
  • C. Based on the method parameters
  • D. Based on the order in which methods are declared

Based on the object type of the instance

Based on the object type of the instance

4.What is the key reason why private methods cannot be overridden?
  • A. Because private methods belong to the object, not the class
  • B. Because private methods are not inherited by subclasses
  • C. Because private methods are resolved at runtime
  • D. Because private methods can only be accessed using reflection

Because private methods are not inherited by subclasses

Because private methods are not inherited by subclasses

5.Can method overloading be achieved by changing only the return type of a method?
  • A. Yes, because return type is part of method signature
  • B. No, because return type alone does not differentiate methods
  • C. Yes, but only in abstract classes
  • D. No, because method overloading only works with constructors

No, because return type alone does not differentiate methods

No, because return type alone does not differentiate methods