Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions methods/method.go
Original file line number Diff line number Diff line change
@@ -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()
}