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

What is the difference between public, private, protected, and friend access?

817


What does int argc char * argv [] mean?

751


What is set in java?

798


Can a top level class be private or protected?

810


Give differences between Quicksort &Mergesort. When should these sorts be used andwhat is their running time in java?

979


What are the types of arrays in java?

853


Explain inheritance in java?

801


What is navigable map in java?

777


How do I start learning java?

820


How do you create a method in java?

770


Can inner class have constructor?

786


What is the differences between c++ and java? Explain

840


Can we define static methods inside interface?

756


What are controls and their different types in awt?

871


What is parsing a string?

876