What will be the output of the following code snippet: public int add(int a, long b) { return a + b; } and public long add(int a, int b) { return a + b; }?
- Compilation Error: Ambiguous method call.
- Compilation Error: Duplicate method add with the same parameter types.
- Compilation Error: Mismatched return types.
- The code will run without errors, and the output will be the sum of a and b.
The code will result in a compilation error because both methods have the same name and the same parameter types (int and long). Java does not allow you to overload methods based solely on the return type. Overloaded methods must have different parameter lists. Overloading based on return types would lead to ambiguity.
Loading...
Related Quiz
- Which data structure is preferred for implementing Binary Search effectively?
- The ________ interface provides methods to retrieve the meta data of the database such as its structure (tables, schemas), the user on the connection, etc.
- Imagine a situation where you need to insert a large dataset (for example, 10,000 rows) into a database using JDBC. How would you optimize this process to ensure that it is done efficiently and does not consume excessive resources?
- The method read() of FileReader class returns ________ when the end of the file is reached.
- What will be the initial capacity of a HashSet when no size is defined during its creation?