From 5d48885db3d1d99d0c935154fc9926763785cffa Mon Sep 17 00:00:00 2001 From: satya <38804803+satyamuralidhar@users.noreply.github.com> Date: Fri, 24 Jul 2020 09:44:42 +0530 Subject: [PATCH] Create method.go --- methods/method.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 methods/method.go diff --git a/methods/method.go b/methods/method.go new file mode 100644 index 00000000..66bbfd52 --- /dev/null +++ b/methods/method.go @@ -0,0 +1,31 @@ +package main +import "fmt" +//creating structures +type student struct { + name string + age int + percentage float64 +} +type teacher struct { + name string + age int +} +//creating same methods but different types of receivers +func (s student) show() { + fmt.Println("name of the student: ",s.name) + fmt.Println("age of the student: ",s.age) + fmt.Println("percentage of the student", s.percentage) +} +func (t teacher) show() { + fmt.Println("name of the teacher: ", t.name) + fmt.Println("marks", t.age) +} +// main method +func main() { + //initialise value of structures + val1 := student{"satya",24,78.5} + val2 := teacher{"subbu",30} + //calling methods + val1.show() + val2.show() +}