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
What is the format specifier?
When is an object subject to garbage collection?
How do you replace all in word?
How do you test a method for an exception using junit?
Explain java heap space and garbage collection?
what is the significance of listiterator in java?
What are JVM.JRE, J2EE, JNI?
Is break statement can be used as labels in java?
Print Vertical traversal of a Binary Tree.
Why we use multi threading instead of multiprocessing?
Why are there no global variables in java?
What is the use of a copy constructor?
Explain the use of volatile field modifier?
How do constructors use this() and super()?
Is map sorted in java?