个性化阅读
专注于IT技术分析

F#方法覆盖

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

type Employee() =
 class
  abstract ShowName : unit -> unit
  default this.ShowName() = printfn"This is base class method"
 end

type Manager() =
 class
  inherit Employee()
  override this.ShowName() = printf "This is derived class method"
 end

let employee = new Employee()
let manager = new Manager()
employee.ShowName()
manager.ShowName()

输出:

This is base class method
This is derived class method
赞(0)
未经允许不得转载:srcmini » F#方法覆盖

评论 抢沙发

评论前必须登录!