VOOZH about

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

⇱ Polymorphism in GoLang - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Polymorphism in GoLang

Last Updated : 15 Jul, 2025

Polymorphism is the ability of a message to be displayed in more than one form. Polymorphism is considered one of the important features of Object-Oriented Programming and can be achieved during either 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 exampleExample 1:
 


Output: 
 

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 implements the interface which helps interfaces to achieve polymorphism in the Golang. The following example explains the concept of polymorphism:Example 2:
 


Output: 
 

Total Time is 2060 minutes.


 

Comment

Explore