Abstraction OOP

Run Settings
LanguageGo
Language Version
Run Command
package main import "fmt" type Animal interface { Speak() } type Dog struct { Name string } func NewDog(name string) *Dog { return &Dog{Name: name} } func (d Dog) Speak() { fmt.Printf("%s says Woof!\n", d.Name) } type Cat struct { Name string } func NewCat(name string) *Cat { return &Cat{Name: name} } func (c Cat) Speak() { fmt.Printf("%s says Meow!\n", c.Name) } func main() { dog := NewDog("Buddy") cat := NewCat("Whiskers") animals := []Animal{dog, cat} for _, animal := range animals { animal.Speak() } }
Editor Settings
Theme
Key bindings
Full width
Lines