Created
September 4, 2018 11:31
-
-
Save viveksyngh/53317df6675c5dab882643e9b1a2bd1d to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
| ) | |
| //Person struct to store person information | |
| type Person struct { | |
| FirstName string | |
| LastName string | |
| } | |
| func (p Person) getFullName() string { | |
| return p.FirstName + " " + p.LastName | |
| } | |
| //Student struct to represent student | |
| type Student struct { | |
| Person //A `Person` type field without any name | |
| University string | |
| } | |
| func main() { | |
| p := Person{FirstName: "John", LastName: "Doe"} | |
| s := Student{Person: p, University: "Stanford"} | |
| fmt.Printf("First Name: %s\n", s.FirstName) | |
| fmt.Printf("Last Name: %s\n", s.LastName) | |
| fmt.Printf("Full Name: %s\n", s.getFullName()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment