Polymorphism OOP

Run Settings
LanguageGo
Language Version
Run Command
package main import "fmt" type Shape interface { Area() float64 } type Circle struct { Radius float64 } func NewCircle(radius float64) *Circle { return &Circle{Radius: radius} } func (c Circle) Area() float64 { return 3.14 * c.Radius * c.Radius } type Rectangle struct { Width float64 Height float64 } func NewRectangle(width, height float64) *Rectangle { return &Rectangle{Width: width, Height: height} } func (r Rectangle) Area() float64 { return r.Width * r.Height } func CalculateArea(s Shape) { fmt.Printf("Area: %f\n", s.Area()) } func main() { circle := NewCircle(5.0) rectangle := NewRectangle(4.0, 6.0) CalculateArea(circle) CalculateArea(rectangle) }
Editor Settings
Theme
Key bindings
Full width
Lines