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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is "this" keyword in java? Explain

1048


What is bean? Where it can be used?

1021


Why java is used everywhere?

950


What do you understand by copy constructor in java?

877


How do you differentiate abstract class from interface?

912


How to display arraylist values in java?

950


Can you explain the private protected field modifier?

961


How to add menushortcut to menu item?

944


Is java hashset ordered?

1047


What is difference between next () and nextline () in java?

935


what r advatages of websphere? & how to deploy?

2100


Describe the Big-O Notation.

996


What class of exceptions are generated by the java run-time system?

1118


Explain garbage collection in java?

914


Explain the difference between arraylist and linkedlist in java?

907