Skip to content

Commit 5d48885

Browse files
Create method.go
1 parent 46695d8 commit 5d48885

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

methods/method.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
import "fmt"
3+
//creating structures
4+
type student struct {
5+
name string
6+
age int
7+
percentage float64
8+
}
9+
type teacher struct {
10+
name string
11+
age int
12+
}
13+
//creating same methods but different types of receivers
14+
func (s student) show() {
15+
fmt.Println("name of the student: ",s.name)
16+
fmt.Println("age of the student: ",s.age)
17+
fmt.Println("percentage of the student", s.percentage)
18+
}
19+
func (t teacher) show() {
20+
fmt.Println("name of the teacher: ", t.name)
21+
fmt.Println("marks", t.age)
22+
}
23+
// main method
24+
func main() {
25+
//initialise value of structures
26+
val1 := student{"satya",24,78.5}
27+
val2 := teacher{"subbu",30}
28+
//calling methods
29+
val1.show()
30+
val2.show()
31+
}

0 commit comments

Comments
 (0)