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

Is nan false?

722


What are advantages of exception handling in java?

785


How to Sort Strings which are given in List and display in ascending order without using java api.

4075


What is string [] args?

783


What do you mean by garbage collection used in java?

788


Why java is a platform independent? Explain

747


What does bitwise or mean?

801


How can we make copy of a java object?

766


How do you add an element to an arraylist in java?

679


What is xslt in java?

723


Is java a security risk?

789


What is the difference between delete and delete[]

900


Is java free for businesses?

777


How do you declare an array that will hold more than 64KB of data?

913


What is variable argument in java?

766