Skip to content

Commit

Permalink
add: go interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hthuz committed Jul 1, 2024
1 parent bec4e36 commit ed47468
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions go/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import "fmt"

type Animal interface {
Bark()
}

type Dog struct {
name string
}

type Cat struct {
name string
}

func (d Dog) Bark() {
fmt.Println("W")
}

func (c Cat) Bark() {
fmt.Println("C")
}

func main() {
var d = Dog{"dog"}
var c = Cat{"cat"}
var in_d = Animal(d)
var in_c = Animal(c)
in_d.Bark()
in_c.Bark()
}

0 comments on commit ed47468

Please sign in to comment.