Created
March 5, 2018 06:54
-
-
Save MuthukumarHelios/0218ede8c40eb0594f42f50878132b2c to your computer and use it in GitHub Desktop.
Struct vs interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type student struct{ | |
name string | |
age int | |
lastName string | |
} | |
type studentI interface{ | |
GetAge() int | |
GetFullName() string | |
GetName() string | |
} | |
func StudentDetails(si studentI){ | |
fmt.Println(si) | |
fmt.Println("student age",si.GetAge()) | |
fmt.Println("student Full name", si.GetFullName()) | |
fmt.Println("student Name", si.GetName()) | |
} | |
func (s student) GetAge() int { | |
return s.age | |
} | |
func (s student) GetFullName() string{ | |
return s.name + s.lastName | |
} | |
func (s student)GetName() string{ | |
return s.name | |
} | |
func main(){ | |
v := student{name: "muthu", age: 22, lastName: "kumar"} | |
StudentDetails(v) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment