Created
March 11, 2017 23:00
-
-
Save mjgpy3/92e5b4856c6c7e76b3b1dc8c01794fd4 to your computer and use it in GitHub Desktop.
F# Inheritance Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Person(name: string) = | |
member this.GetName () = name | |
type Employee(name: string, id: int) = | |
inherit Person(name) | |
member this.GetId () = id | |
member val Id = id with get, set | |
member this.SetId (newId: int) = | |
this.Id <- newId | |
let steve = Employee ("Steve", 666) | |
let toString (e: Employee) = | |
sprintf "name=%s, id=%d" (e.GetName ()) e.Id | |
printfn "%s" (toString steve) | |
steve.Id <- 6666 | |
printfn "%s" (toString steve) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment