Difference between over loading and over ridding?

Answer Posted / manish kushwaha

Hi All,
These two are very powerful concept in Java. I would like
to explain in veru simple way hope we will get it easily

1) Method OverLoading...
Always this concept comes with Same Name of methods

1) Mthod name should be same
2) Return type can be differ of methods
3) Most Important Condition is
a) Type of Parameter in methods
b) Number of paramenter in methods
c) Order of parameter in methods

Exp. 1 public void foo(String str a, int b){}
2 public int foo(int a, int b, int c){ }
3 public void foo(int a , double b){}
4 public void foo(double b , int a){}
5 public int foo(int a, int b, int c, int
d){ }

Like in above example one method can have any TYPE
of PARAMETER, 2,5 example of NUMBER of PARAMETER, 3,4
example of ORDER of parameter.
**Make sure that method overriding can be done in
same class and Sub/Super class both


2) Method Overriding.
Always method over riding happens only in Sub/Super
class concept
We have one method in super class and same method
in sub class with
1) Same mthod name
2) same method return type
3) same type of parameter
if above condition match then you can say this is
method over ring.....

Exp. Class A{
public int foo(int a, int b){}
}
Class B extends A{
public int foo(int d, int e){}
}
obove scenario is method over riding.

* Always Method overloading happens in Compile time
* Always method over riding happens in Run time.


Hope you got the concept.....
Thanks Manish

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is overloading in oops?

596


What is coupling in oops?

591


What is the types of inheritance?

596


What is constructor in oop?

584


What is the important feature of inheritance?

631






There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.

1453


What is static in oop?

585


What is class in oop with example?

612


What is solid in oops?

598


write a program to find 2 power of a 5digit number with out using big int and exponent ?

1891


What is the importance of oop?

605


What is polymorphism in oops with example?

525


officer say me - i am offered to a smoking , then what can you say

1576


What is the difference between abstraction and polymorphism?

609


any one please tell me the purpose of operator overloading

1962