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
Why does java have two ways to create child threads? Which way is better?
What is the use of http-tunneling in rmi?
What are the two basic ways in which classes that can be run as threads may be defined?
What is Java Reflection API? Why it’s so important to have?
What is unicode used for?
What is the structure of java?
whatis Home interface and Remoteinterface? with example?
How do you identify if jvm is 32-bit or 64-bit from java program?
What is compiler and what its output.
Is java hard to learn?
What are the rules for variable declaration?
How to display all the prime numbers between 1 and 100
what do you understand by the term string with respect to java?
What is exception handling in java?
What are synchronized blocks in java?