File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments