In Go structure, the working of promoted methods is just like Promoted Fields. We use this concept in the nested structure where a structure is a field in another structure, simply by just adding the name of the structure into another structure and it behaves like the Anonymous Field to the nested structure. And the methods of that structure (other than nested structure) are the part of the nested structure, such type of methods are known as Promoted Methods. Or in other words, prompted methods are those methods which are implemented by the child structure, and is accessible by the parent structure.
- If the child and the parent structure contain a method that has the same name but different type of receiver, then both the methods are available in the parent structure as shown in Example 2. Here both child and parent structure contain methods of the same names.
- If child structure contains two methods with the same name and same receiver, then these methods are not promoted in the parent structure and if you try to do, then the compiler will give an error.
Name: Sumit Age: 28 Gender: Male Per day salary: 890 Total Salary: 26700 Post: HR Employee id: 4567
Name: Sumit Age: 28 Gender: Male Per day salary: 890 Total Salary: 150 Post: HR Employee id: 4567 Total Articles: 150
- Promoted Fields in Golang Structure
- Methods in Golang
- Methods With Same Name in Golang
- Structure Equality in Golang
- Anonymous Structure and Field in Golang
- Nested Structure in Golang
- Function as a Field in Golang Structure
- Checking if structure is empty or not in Golang
- Printing structure variables in console in Golang
- How to convert a slice of bytes in uppercase in Golang?
- Golang program that uses fallthrough keyword
- math.Lgamma() Function in Golang with Examples
- math.Float64bits() Function in Golang With Examples
- How to check equality of slices of bytes in Golang?
- atomic.AddInt64() Function in Golang With Examples
- atomic.StoreInt64() Function in Golang With Examples
- reflect.FieldByIndex() Function in Golang with Examples
- string.Contains Function in Golang with Examples
- bits.Sub() Function in Golang with Examples
- How to convert a slice of bytes in lowercase in Golang?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.