Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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



There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

There are 2 methods in a class. Both have the same method signature except for return types. Is thi..

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

Post New Answer

More Core Java Interview Questions

What is the basic concepts of OOPS?

0 Answers   BlackRock,


What is the difference between Java Bean and Java Class.?

2 Answers  


Can i have abstract class with no abstract methods?

22 Answers   CTS,


What is the difference between sleep and wait in java?

0 Answers  


What does  mean in regex?

0 Answers  


What environment variables do I need to set on my machine in order to be able to run java programs?

0 Answers  


What are internal variables?

0 Answers  


Variable of the boolean type is automatically initialized as?

0 Answers  


Should you use singleton pattern?

0 Answers  


What are the differences between include directive and include action?

0 Answers  


How to create packages in java?

0 Answers  


What is finally in exception handling?

7 Answers  


Categories