add methods from another package

This commit is contained in:
Aliberk Sandıkçı 2023-07-24 10:47:36 +03:00
parent 7d794d53e6
commit 97742e6172
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
2 changed files with 18 additions and 0 deletions

View File

@ -24,4 +24,12 @@ func main() {
car3_1.Name = "ford"
// car3_1.color = "green" // undefined
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)
}

View File

@ -32,6 +32,16 @@ func (c Car3) String() string {
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() {
fmt.Println("Hello World (go-organization/simple-structure/package-str/great/great.go)")
}