Исходники и презентации
This commit is contained in:
30
lessons/structs/inheritance/main.go
Normal file
30
lessons/structs/inheritance/main.go
Normal file
@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func (p *Person) Intro() string {
|
||||
return p.Name
|
||||
}
|
||||
|
||||
type Woman struct {
|
||||
Person
|
||||
}
|
||||
|
||||
func (w *Woman) Intro() string {
|
||||
return "Mrs. " + w.Person.Intro()
|
||||
}
|
||||
|
||||
func main() {
|
||||
woman := Woman{
|
||||
Person: Person{
|
||||
Name: "Ekaterina",
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println(woman.Intro())
|
||||
fmt.Println(woman.Person.Intro())
|
||||
}
|
||||
Reference in New Issue
Block a user