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?
Answers were Sorted based on User's Feedback
Answer / shamsherabanu
It is not overloading because overloading must have different parameters, no matter what ever may be the return type is.
And for overriding inheritance should be used between 2 classes.
so it is neither overriding nor overloading.
It just show compilation error as method is already defined in
same class
Is This Answer Correct ? | 12 Yes | 0 No |
Answer / ashu_deepu
it is not overloading bcos different return types does not mean overloading.
n 4 overriding inheritance should b used between 2 classes.
so it is neither overriding nor overloading.
Is This Answer Correct ? | 8 Yes | 0 No |
Answer / debapriya
Niether overloading nor ovverriding ,this question has errors
Overloading---->different method
signatures(order,type,number different)
Ovveriding signature same but subclass can implement this method
So ??????????????.
Is This Answer Correct ? | 9 Yes | 2 No |
Answer / s.ramesh
public class sample
{
public void displayValue (int a, int b)
{
System.out.println("a = "+a +" b = "+b);
}
public int displayValue (int a, int b)
{
System.out.println("a+b:"+(a+b));
return (a+b);
}
public static void main(String[] args)
{
sample t = new sample();
t.displayValue(10,10);
int x = t.displayValue(20,30);
}
}
Output:
D:\Prg>javac sample.java
sample.java:8: displayValue(int,int) is already defined in
sample
public int displayValue (int a, int b)
^
sample.java:18: incompatible types
found : void
required: int
int x = t.displayValue(20,30);
^
2 errors
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / debapriya maity
See overloading has nothing to do with Covariant Return
types ,in fact overloading dosent take into consideration
the return types.
But in case of ovveriding u can provide Covariant return type
say for example
class A {
protected A getModel(){
return this;
}
}
class B extends A{
public B getModel(){
return this
}
}
and there are many other examples of
covariant return types like this.
Since B is A(IS-A RelationShip)
so the return type can be a subclas of the super class
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / jan
The above program excute's fine ,This is overloading
In overloading concept return type in not Mandatory.
If my answer is not correct , please let me know
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / 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 |
Answer / vikneswarank
Its a overLoading .because overriding have two diff class
and return type also same
but overloading have one class,and it have same method name
and diff signature.
Is This Answer Correct ? | 3 Yes | 8 No |
Answer / mohamed yehiya
If both signature are same, i.e parameters
and if the method has co-variant return type
which means return type of int in one method and
return type of long in another method.
Consider safely as the method is overloaded.
if otherwise it's neither overloaded or overrided
just an another method in the class.
Is This Answer Correct ? | 0 Yes | 5 No |
how can i connect to database in a applet ?
What are the different approaches to implement a function to generate a random number?
0 Answers Axtria, ITC Indian Tobacco Company,
I want to re-reach and use an object once it has been garbage collected. Define how it’s possible?
Explain different types of wrapper classes in java?
What is a conditional equation?
What is update method called?
how to minimize the functionality to will not force garbage collector?
Name and explain the types of ways which are used to pass arguments in any function in java.
what are the differences between final,finally,finalize methods?
what is the major difference between linkedlist and arraylist in java?
What do you mean by synchronized non access modifier?
What is type casting?