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...

Difference between overloading and Overriding. <Giving a
confusing example to test the concept.>
(also asked in PA Consultancy Group,iflex,Value
chain,IBM,CTS,Accenture, Tarang>

Answer Posted / ravikant baluni

Method overloading:
-------------------
Method overloading means having two or
more methods with the same name but different signatures in
the same scope. These two methods may exist in the same
class or anoter one in base class and another in derived
class.

Like if we have a method: void sum(int a,int b){---} then
it can be overloaded as:
void sum(int a,int b,int c);
void sum(string s1,string s2);

Method overriding:
------------------
Method overriding means having a
different implementation of the same method in the
inherited class. These two methods would have the same
signature, but different implementation. One of these would
exist in the base class and another in the derived class.
These cannot exist in the same class.

Like if we have a method: int fun(int a,int b){---} then it
can be overrided as:
int fun(int a,int b)
{
return (a+b);
}



int fun(int a,int b)
{
return (a*b);
}


int fun(int a,int b)
{
return (a/b);
}

Is This Answer Correct ?    14 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

There are two classes named classa and classb. Both classes are in the same package. Can a private member of classa can be accessed by an object of classb?

1493


How will you calculate the depth of a binary tree if the tree contains 15 nodes?

1084


What is main difference between variable and constant?

1038


Is java programming easy?

1004


explain the difference between jdk and jvm?

999


What is the char data type?

1003


What happens if main method is not static?

1000


What is generic type?

1031


Why hashset is used in java?

1080


Is ++ operator is thread safe in java?

965


Is it possible to instantiate the abstract class?

956


Can we override protected method in java?

1067


Is singleton a bad practice?

1050


What are namespaces in java?

1042


What is a file pointer?

1085