VOOZH about

URL: https://www.geeksforgeeks.org/go-language/inheritance-in-golang/

⇱ Inheritance in GoLang - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Inheritance in GoLang

Last Updated : 22 Jun, 2020
Inheritance means inheriting the properties of the superclass into the base class and is one of the most important concepts in Object-Oriented Programming. Since Golang does not support classes, so inheritance takes place through struct embedding. We cannot directly extend structs but rather use a concept called composition where the struct is used to form other objects. So, you can say there is No Inheritance Concept in Golang. In composition, base structs can be embedded into a child struct and the methods of the base struct can be directly called on the child struct as shown in the following example. Example 1: Output:
Universe is: MCU
Universe is: DC
Multiple inheritances take place when the child struct is able to access multiple properties, fields, and methods of more than one base struct. Here the child struct embeds all the base structs as shown through the following code: Example 2: Output:
In base struct 1.

In base struct 2.
Comment

Explore