方法覆盖是面向对象编程方法的功能。它有助于实现多态性。我们可以使用继承实现方法重写。让我们来看一个例子。
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
评论前必须登录!
注册