add methods from another package
This commit is contained in:
parent
7d794d53e6
commit
97742e6172
2 changed files with 18 additions and 0 deletions
|
@ -24,4 +24,12 @@ func main() {
|
||||||
car3_1.Name = "ford"
|
car3_1.Name = "ford"
|
||||||
// car3_1.color = "green" // undefined
|
// car3_1.color = "green" // undefined
|
||||||
fmt.Println(car3_1)
|
fmt.Println(car3_1)
|
||||||
|
|
||||||
|
fmt.Printf("\n\n")
|
||||||
|
|
||||||
|
// car1.reset() // also functions/methods cannot be used outside of package itself
|
||||||
|
|
||||||
|
car1.Reset2() // works
|
||||||
|
fmt.Println(car1)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,16 @@ func (c Car3) String() string {
|
||||||
return fmt.Sprintf("car color:%q | name:%q", c.color, c.Name)
|
return fmt.Sprintf("car color:%q | name:%q", c.color, c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Car) reset() {
|
||||||
|
c.Name = ""
|
||||||
|
c.Color = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Car) Reset2() {
|
||||||
|
c.Name = ""
|
||||||
|
c.Color = ""
|
||||||
|
}
|
||||||
|
|
||||||
func Hello() {
|
func Hello() {
|
||||||
fmt.Println("Hello World (go-organization/simple-structure/package-str/great/great.go)")
|
fmt.Println("Hello World (go-organization/simple-structure/package-str/great/great.go)")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue