Created
March 11, 2022 02:05
-
-
Save didi1246888/30e381057b6aa2cb9f40c249a889f505 to your computer and use it in GitHub Desktop.
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 { // abstract field | |
name string | |
} | |
func (person *Person) setName(name string) { // Encapsulation method | |
person.name = name | |
} | |
func (person *Person) GetInfo() { // Encapsulation method | |
fmt.Println(person.name) | |
} | |
func main() { | |
p := Person{"night guard"} | |
p.setName("sam") | |
p.GetInfo() // output new name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment