Method Overriding
changing a parent's method in child with
different action/behavior (method arguments and return type must be
the same). You can only override methods from parent which are
declared as public in parent; child does not see any methods defined
in parent as private.
Example of Method Overriding:
//here is the
parent class
public class Info {
private int type;
public int tryIt(int i) {
return i;
}
}
//here is the
child class
//and the overidden method tryIt
//in the child -- same return, same args, different
//action in body
public class NewInfo
extends Info {
private int type;
public int tryIt(int i) {
int x;
x = i * 5;
return x;
}
}
|