method overloading and method overriding java
method overloading vrs method overriding
difference between method overloading and method overriding
Method Overloading:-
Method Overloading occurs with in the class. When any class have more than one method with same name and different parameter.
Class A{
public int add(int x, int y){
// implimentation
}
public String add(int x, int y, int z){
// implimentation
}
}
Method Overriding:-
Method Overriding occurs with in the Parant class and Child (Derived) class. When both class have same method name with same signature.
Class A{
public int add(int x, int y){
// implimentation
}
}
Class B extends A{
}
}
difference between method overloading and method overriding
Method Overloading:-
Method Overloading occurs with in the class. When any class have more than one method with same name and different parameter.
Class A{
public int add(int x, int y){
// implimentation
}
public String add(int x, int y, int z){
// implimentation
}
}
Method Overriding:-
Method Overriding occurs with in the Parant class and Child (Derived) class. When both class have same method name with same signature.
Class A{
public int add(int x, int y){
// implimentation
}
}
Class B extends A{
public int add(int x, int y){
// implimentation}
}
Comments
Post a Comment