structs

No inheritance

type Dog struct {
    Breed string 
    Weight int
}

type Cat struct {
}

Creation

poodle := Dog{"Poodle", 34}
poodle := Dog{Breed: "Poodle", Weight: 34}
jaguar := Cat{}

Printing

fmt.Println(poodle) //outputs "Poodle 34" 
fmt.Printf("%+v", poodle) //outputs {Breed:Poodle Weight:34}

Methods

After declaring a type as above

Last updated