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

What is static in java?

561


What is the difference in between cpp and java? Can u explain in detail?

607


Differentiate between static and non-static methods in java.

571


Which programming language is best in future?

527


What does index mean in java?

542






Explain the importance of join() method in thread class?

640


What is difference between call by value and call by reference?

503


How to display arraylist values in java?

490


What classes of exceptions may be caught by a catch clause in java programming?

704


What is method reference?

517


How do you convert boolean to boolean?

525


How to convert string to byte array and vice versa?

586


Why pass by reference is not possible in java?

498


How does multithreading take place on a computer with a single cpu?

544


How is Object Oriented Programming different from Procedure Oriented Programming?

593