Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Created September 4, 2018 11:31
Show Gist options
  • Select an option

  • Save viveksyngh/53317df6675c5dab882643e9b1a2bd1d to your computer and use it in GitHub Desktop.

Select an option

Save viveksyngh/53317df6675c5dab882643e9b1a2bd1d to your computer and use it in GitHub Desktop.
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