There are 2 methods in a class. Both have the same method
signature except for return types. Is this overloading or
overriding or what is it?

Answer Posted / ashish

it is overloading not overriding.
not overriding bcz two methods are in same class and
overriding is when one class extends another class and
overrides its methods.
how overloading?
see the Example:
class Ashu
{
int a,b;

int add(int x,int y)
{
int z=x+y;
return z;
}
void add(double x, double y)
{
double z=x+y;
System.out.println(z);
}
}
class Ashish
{
public static void main(String args[])
{
Ashu obj=new Ashu();
obj.add(10.7,20.9);
int a=obj.add(10,20);
System.out.println(a);
}
}

here return types are not same but parameters are same. now
in main pogram integer or double parameters in different
calls by the object account for method overloading.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

State the difference between strings and arrays.

866


Can a class have 2 constructors?

679


How do you declare a variable?

842


What is the abstract class?

777


What is jit and its use?

777


Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.

835


What is a parameter in matrices?

764


Can we define static methods inside interface?

738


Why main() method is public, static and void in java ?

848


How do I find and replace in word?

742


How many types of memory areas are allocated by jvm?

774


What is meant by binding in rmi?

785


What is the difference between a method and a function in alice?

817


What is array length in java?

737


Can constructor be protected in java?

732