public class B {
public void add(int a, int b) {}
protected void multiply(int a, int b, float c) {}
public float sum(float a, float b) {return a+b;}
public static void main(String args[]){}
}
class C extends B{
public void add(int a, int b){}
// Overriding (Same method name(add), same argument lists)
public void add(int a, int b, int c){}
// Not an Override (Its a new method).
// Its an Overloaded method(same name, different arguments).
// Overridden method should have same argument lists
public void multiply(int a, int b, float c) {}
// Overriding (Same method name(multiply), same argument lists)
//private void multiply(int a, int b, float c) {}
// Error:Cannot reduce the visibility of the inherited method
public float sum(float a, float b) {return a+b;}
// Overriding (Same method name(sum), same argument lists, same return type)
public float sum(float a, int b) {return a+b;}
// Not an override.
// Its an Overloaded method(same name, different arguments).
//public double sum(float a, int b) {return a+b;}
// Error:Duplicate method sum(float, int).
// Not an override.(Overridden method should have same return type)
// Not an overload.(Cant change only the return type)
// Overloaded method must have different argument lists.
}
0 Comments
|