---
title: "Why method overloading is not possible by changing the return type in java?"  
description: "Why method overloading is not possible by changing the return type in java?"  
author: "Samuel Fernandes"  
published: 2015-03-30  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/2376/why-method-overloading-is-not-possible-by-changing-the-return-type-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Why method overloading is not possible by changing the return type in java?

n java, method overloading is not possible by changing the return type of the method because there may occur ambiguity.here is an example which state how ambiguity might occur:\
here how java determine which method to call \
\

```
class Calculation3{    int sum(int a,int b){System.out.println(a+b);}    double sum(int a,int b){System.out.println(a+b);}      public static void main(String args[]){    Calculation3 obj=new Calculation3();    int result=obj.sum(20,20); //Compile Time Error      }  }   
```

## Answers

### Answer by Anonymous User

n java, method overloading is not possible by changing the return type of the method because there may occur ambiguity.here is an example which state how ambiguity might occur:\
here how java determine which method to call \
\

```
class Calculation3{    int sum(int a,int b){System.out.println(a+b);}    double sum(int a,int b){System.out.println(a+b);}      public static void main(String args[]){    Calculation3 obj=new Calculation3();    int result=obj.sum(20,20); //Compile Time Error      }  }   
```


---

Original Source: https://www.mindstick.com/interview/2376/why-method-overloading-is-not-possible-by-changing-the-return-type-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
