Example Function that takes an interface type as value and pointer?

package main
import "fmt"
type Showprice interface {
    display(int)
}
func display(s Showprice, price int) {	
    s.display(price)
}
type Car struct {
    Price int
}
func (c Car) display(price int) {
    c.Price = price
}
type Bike struct {
    Price int
}
func (b *Bike) display(price int) {
    b.Price = price
}
func main() {
	ca := Car{Price:2000}
    bi := Bike{Price:400}    
    display(ca, 3000)
    display(&bi, 600)
    fmt.Println("Car:",ca.Price)
    fmt.Println("Bike:",bi.Price)
}
C:\golang\codes>go run example.go
Car: 2000
Bike: 600

C:\golang\codes>

Thanks for reading. Please leave your valuable feedback and comments.

* Required Fields

No questions yet. Be the first to ask the question!