Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create method.go for exmaples of go #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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()
}