Last active
March 24, 2018 19:13
-
-
Save doron2402/7fbe2dfd8530f509be9737cabb5d68ff to your computer and use it in GitHub Desktop.
Golang prototype
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 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()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple GoLang prototype