From 57942eb8a0b9e24414b8e03d8a8c3eac4979bd86 Mon Sep 17 00:00:00 2001 From: Jian Han Date: Sat, 10 Mar 2018 23:34:31 +1000 Subject: [PATCH] Added oct cat example --- openclose/main.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 openclose/main.go diff --git a/openclose/main.go b/openclose/main.go new file mode 100644 index 0000000..4d7cd12 --- /dev/null +++ b/openclose/main.go @@ -0,0 +1,29 @@ +package main + +import "fmt" + +type Cat struct { + Name string +} + +func (c Cat) Legs() int { + return 4 +} + +func (c Cat) PrintLegs() { + fmt.Printf("I have %d legs", c.Legs()) +} + +type OctCat struct { + Cat +} + +func (o OctCat) Legs() int { + return 5 +} + +func main() { + var oct OctCat + fmt.Println(oct.Legs()) + oct.PrintLegs() +}