← All Exercises

Go Interface Implementation

intermediatego~20min

Background

Go interfaces are satisfied implicitly, enabling flexible polymorphism without explicit declarations.

Problem

Create a Shape interface with Area and Perimeter methods, and implement it for Circle and Rectangle types.

Input

A Shape interface value (either Circle or Rectangle).

Output

The area and perimeter computed by the concrete implementation.

Sample tests

Sample 1

Input: Circle{radius:5}
Expected: area=78.54, perimeter=31.42

Your solution

Learning objective

Learn implicit interface satisfaction, multiple implementations, and polymorphic dispatch in Go.