Introduction to OOP Chapter 16: Overriding : next previous audio real text

Notating Overriding

In some languages (Smalltalk, Java) overriding occurs automatically when a child class redefines a method with the same name and type signature.

In some languages (C++) overriding will only occur if the parent class has declared the method in some special way (example, keyword virtual).

In some languages (Object Pascal) overriding will only occur if the child class declares the method in some special way (example, keyword override).

In some languages (C#, Delphi) overriding will only occur if both the parent and the child class declare the method in some special way.

class Parent {   // C# example
   public virtual int example (int a) { ... }
}
class Child : Parent {
   public override int example (int a) { ... }
}
Intro OOP, Chapter 16, Slide 06