| Introduction to OOP | Chapter 16: Overriding : | next | previous | audio | real | text |
class Parent {
Mammal test ( ) {
return new Cat();
}
}
class Child extends Parent {
Animal test () {
return new Bird();
}
}
Parent aParent = new Child();
Mammal result = aValue.test(); // is this legal?
Most languages subscribe to the novariance rule: no change in type signatures.