Skip to content

Instantly share code, notes, and snippets.

@doron2402
Last active March 24, 2018 19:13
Show Gist options
  • Save doron2402/7fbe2dfd8530f509be9737cabb5d68ff to your computer and use it in GitHub Desktop.
Save doron2402/7fbe2dfd8530f509be9737cabb5d68ff to your computer and use it in GitHub Desktop.
Golang prototype
package main
import "fmt"
type person struct {
firstName string
lastName string
age float32
id int
}
type student struct {
person
gradeAverage float32
classes []string
}
func (p person) sayHi() {
fmt.Println(`Hi`)
}
func (p person) greet() {
fmt.Println(`Hi, I'm`, p.firstName, p.lastName)
}
func (s student) greet() {
fmt.Println(`Hi, I'm a student`, s.firstName)
}
func (s student) getAvgGrade() float32 {
return s.gradeAverage
}
func main() {
tmpP := person{
firstName: "John",
lastName: "Smith",
age: 50,
id: 1234,
}
tmpP.sayHi()
tmpP.greet()
// Create student
tmpStudent := student{
person{
"Johnny",
"Smithy",
16,
3333,
},
83.56,
[]string{"Math", "English", "CS"},
}
fmt.Println(tmpStudent.getAvgGrade())
}
@doron2402
Copy link
Author

Simple GoLang prototype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment