This is a creation in
Article, where the information may have evolved or changed.
typeBasestruct{FirstName, LastNamestringAgefloat32}func(Base *base) Hasfeet () {fmt. Println (base. FirstName + base. LastName +"has feet! Base ")}func(Base *base) Flying () {fmt. Println ("Base Can flying!")}typeSubstruct{Base Areastring}func(Sub *sub) Flying () {Sub. Base.flying () fmt. Println ("Sub flying")}funcMain () {chk: =New(Sub) chk. Flying () Chk2: = &sub{base{"Bob","Steven",2.0},"China"} FMT. Println (CHK2. AREA)}
It is important to note that if a subclass overrides a member method of the base class, it needs to call the base class's member method of the same name in the member method of the subclass, and must be called in such an explicit way, rather than in a sub.Base.Flying() sub.Flying() way called an inherited method, so that an infinite loop occurs. The method that has been calling the subclass.
func (sub *Sub) Flying () {Sub. Flying () //infinitely calls itself FMT. Println ( "Sub flying" ) //will never execute here }