Polymorphism is the ability of a message to be displayed in more than one form. Polymorphism is considered as one of the important features of Object-Oriented Programming and can be achieved during either at runtime or compile time. Golang is a light-Object Oriented language and supports polymorphism through interfaces only. Let us first understand the interfaces by the following example:
Area of rectangle: 128.625 unit sq. Area of square: 225.000 unit sq.
Objects of different types are treated in a consistent way, as long as they stick to a single interface, which is the essence of polymorphism. Variable declared in an interface are of interface type. They can take whichever value which implements the interface which helps interfaces to achieve polymorphism in the Golang. The following example explains the concept of polymorphism:
Total Time is 2060 minutes.
- Golang | Polymorphism Using Interfaces
- Zero value in Golang
- Channel in Golang
- Hello World in Golang
- Interfaces in Golang
- Methods in Golang
- Methods With Same Name in Golang
- How to copy a map to another map in Golang?
- Rune in Golang
- Packages in Golang
- Recover in Golang
- Using WaitGroup in Golang
- Closures in Golang
- What is Regex in Golang?
- How to use Ellipsis (...) in Golang?
- Composition in Golang
- Panic in Golang
- Reflection in Golang
- Encapsulation in Golang
- Inheritance 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 firstname.lastname@example.org. 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.