[go: up one dir, main page]

0% found this document useful (0 votes)
4 views4 pages

Polymorph Is M

The document contains a comprehensive list of questions related to method overloading and overriding in Java, aimed at testing understanding of these concepts. It covers various scenarios, edge cases, and rules governing method behavior, including polymorphism. The questions are categorized into two sections: method overloading and method overriding, with additional tricky interview questions for both topics.

Uploaded by

irshad58811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Polymorph Is M

The document contains a comprehensive list of questions related to method overloading and overriding in Java, aimed at testing understanding of these concepts. It covers various scenarios, edge cases, and rules governing method behavior, including polymorphism. The questions are categorized into two sections: method overloading and method overriding, with additional tricky interview questions for both topics.

Uploaded by

irshad58811
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Method Overloading Questions

What is method overloading in Java?


Java Concept Of The Day

What constitutes a method signature in Java?


Java Concept Of The Day

Can overloaded methods have different return types?


Java Concept Of The Day

Is it possible to overload a method by changing only its return type?


Java Concept Of The Day

Can you overload the main method in Java?


Java Concept Of The Day

How does the compiler differentiate between overloaded methods at compile time?
Java Concept Of The Day

Can overloading be achieved by changing only the exceptions thrown?


Java Concept Of The Day

Can overloaded methods be declared static or final?


Java Concept Of The Day

Can you overload methods by altering only the access modifiers (e.g., public vs
private)?
Java Concept Of The Day

What happens when you call an overloaded method with null when multiple candidates
match?
Scientech Easy

Given void msg(Object), void msg(String), void msg(Integer), what does msg(null)
invoke?
Scientech Easy

How do varargs (…) influence overload resolution?


Scientech Easy

Can you overload methods using primitive and their wrapper types interchangeably?
Scientech Easy

How does Java promote numeric types in overloaded methods (e.g., byte→short→int)?
Scientech Easy

What will be the output of calling m1(byte b) when overloads exist for short, int,
Object, and String?
Scientech Easy

Can constructors be overloaded in Java?


Java Concept Of The Day

Is it possible to have two overloaded methods with identical parameters but


different generic type parameters?
DigitalOcean

Can you overload methods by changing only generic type parameters (type erasure
pitfalls)?
DigitalOcean

How does autoboxing/unboxing affect overloaded method selection?


DigitalOcean

Explain an ambiguous overload scenario and why it fails to compile.


Scientech Easy

Method Overriding Questions


What is method overriding in Java?
Java Concept Of The Day

What are the key rules to follow when overriding a method?


Java Concept Of The Day

Can static methods be overridden? What happens instead?


Java Concept Of The Day

What is method hiding, and how does it differ from overriding?


Java Concept Of The Day

Can you override a method’s return type covariantly? Since which Java version?
Java Concept Of The Day

How does overriding interact with checked vs unchecked exceptions (throws clause)?
Java Concept Of The Day

Can you override a private method?


Java Concept Of The Day

How do you invoke the superclass version of an overridden method?


Java Concept Of The Day

Is it possible to override a final method?


Scientech Easy

Can you override a synchronized method?


Scientech Easy

What happens if you reduce the visibility of an overridden method?


Java Concept Of The Day

When both overloading and overriding apply, how does Java choose which method to
call?
Medium

Can you override the equals() and hashCode() methods from Object?
Java Made So Easy

Why must you override equals() and hashCode() together?


Java Made So Easy

What’s the difference between overloading and overriding?


Java Concept Of The Day
Java Concept Of The Day

Can abstract methods be overridden in concrete subclasses?


Java Concept Of The Day
How does covariant return typing adhere to the Liskov Substitution Principle?
Java Concept Of The Day

Explain runtime polymorphism through method overriding.


Codefinity

What pitfalls arise when overriding equals() (e.g., symmetry, transitivity)?


Java Made So Easy

How do interface default methods participate in overriding?

### **Java Polymorphism: 20 Tricky Interview Questions**

1. **What is the difference between compile-time and runtime polymorphism?**


2. **Can you override a private method in Java? Explain.**
3. **How does polymorphism work with static methods?**
4. **Explain dynamic method dispatch with an example.**
5. **What happens if a subclass overrides a method and changes its access modifier
to more restrictive?**
6. **Why can’t static methods be overridden?**
7. **How are instance variables treated in polymorphism? (e.g., accessing via
superclass reference)**
8. **Can you achieve polymorphism without inheritance?**
9. **What is the output of `Animal a = new Dog(); a.sound();` if `Dog` overrides
`sound()`?**
10. **How does polymorphism apply to interfaces?**
11. **Can you use `super` in a polymorphic context to call a parent method?**
12. **Can a subclass override a method and return a subtype (covariant return
type)?**
13. **Does polymorphism work with constructor methods?**
14. **What is method hiding in polymorphism? Give an example.**
15. **How does polymorphism handle exceptions in overridden methods?**
16. **Can you override a `final` method?**
17. **What happens if a subclass overrides a method but changes the parameter list?
**
18. **Explain the use of `instanceof` in polymorphic code.**
19. **Can you cast a superclass object to a subclass type at runtime?**
20. **How does polymorphism work with generic types (e.g., `List<String>` vs.
`List<Integer>`)?**

---

### **Method Overloading: 20 Tricky Interview Questions**

1. **Can you overload methods with the same name but different return types?**
2. **What happens if you pass `null` to an overloaded method with `String` and
`Object` parameters?**
3. **Does Java allow overloading based on `varargs` (e.g., `method(int... x)` vs.
`method(int x)`)?**
4. **Which method is called: `method(int)` or `method(double)` if you pass `5`?**
5. **Can you overload a static method?**
6. **What is type promotion in overloading? Explain with an example.**
7. **Why does `method(Integer)` get called instead of `method(int)` for
`method(10)`?**
8. **Can you overload `main()` in Java?**
9. **What happens if two overloaded methods are equally specific (e.g.,
`method(int, float)` and `method(float, int)`)?**
10. **Does overloading work with inheritance (e.g., subclass adding overloaded
methods)?**
11. **Can you overload a method by changing the order of parameters?**
12. **Why does `method(null)` cause ambiguity between `method(String s)` and
`method(Integer i)`?**
13. **Can you overload methods in the same class with `final` parameters?**
14. **What happens if you overload a method with `int` and `long` and pass a
`byte`?**
15. **Does Java support operator overloading (e.g., `+` for `String`)?**
16. **Can you overload methods with generic types (e.g., `method(List<String>)` vs.
`method(List<Integer>)`)?**
17. **How does autoboxing/unboxing affect overloading?**
18. **Can you overload a method with a subclass parameter (e.g., `method(Animal)`
vs. `method(Dog)`)?**
19. **Why can’t you overload methods by only changing the exception thrown?**
20. **What happens if you overload a method with `Object...` and `String...`
parameters?**

---

### **Method Overriding: 20 Tricky Interview Questions**

1. **Can you override a `static` method?**


2. **What happens if you override a method but change the return type to a non-
covariant type?**
3. **Can you override a method with a broader access modifier (e.g., `protected` to
`public`)?**
4. **Why can’t you override a `final` method?**
5. **How does the `@Override` annotation help in overriding?**
6. **Can you override a method that throws a checked exception with no exception?**
7. **What is the "Fragile Base Class" problem in method overriding?**
8. **Can a subclass override a superclass method and make it `static`?**
9. **What happens if you override `equals()` but not `hashCode()`?**
10. **Can you override a method from an interface?**
11. **How does overriding work with generic methods (e.g., `T method()` in
superclass)?**
12. **Can you override a method with a `synchronized` modifier?**
13. **What is the output if a subclass overrides `toString()`?**
14. **Can you override a private method of the superclass?**
15. **Why can’t you override a method with a more restrictive exception (e.g.,
`IOException` to `Exception`)?**
16. **How does the `super` keyword work in overridden methods?**
17. **Can you override a method in the same class?**
18. **What is the difference between method overriding and method hiding?**
19. **Can you override a constructor?**
20. **What happens if a subclass overrides a method and changes the parameter list?
**

---

These questions test understanding of edge cases, compiler/runtime behavior, and


conceptual clarity. Use code snippets to make them more interactive!

You might also like