Answers for "go method"

Go
0

go method

package main

import (
	"fmt"
)

type Method interface {
	tambah() int
}

type Math struct {
	X, Y int
}

func (ctx *Math) tambah() int {
	return ctx.X + ctx.Y
}

func tambah(ctx Method) int {
	return ctx.tambah()
}

func main() {
	ctx := &Math{20, 20}
	result := tambah(ctx)
	fmt.Println(result)
}
Posted by: Guest on April-03-2021

Browse Popular Code Answers by Language