F#方法覆盖

方法覆盖是面向对象编程方法的功能。它有助于实现多态性。我们可以使用继承实现方法重写。让我们来看一个例子。

type Employee() = classabstract ShowName : unit -> unitdefault this.ShowName() = printfn"This is base class method" endtype Manager() = classinherit Employee()override this.ShowName() = printf "This is derived class method" endlet employee = new Employee()let manager = new Manager()employee.ShowName()manager.ShowName()

【F#方法覆盖】输出:
This is base class methodThis is derived class method

    推荐阅读