Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

We may define default implementations for trait methods. These implementations may be overwritten in types that implement the trait.

Here is a Surface trait that provides a header for a area() method and a default implementation for a describe() method that returns a description of the object:

We define a Rectangle structure that implements the Surface trait:

The Rectangle structure uses the default implementation of the Surface trait:

"Area is 68.40."

Here is a Circle structure that implements the Surface trait too, but also overwrite its describe() method:

We see that Circle’s version of the describe() methods is indeed called in place of the default implementation:

"Circle area is 141.02609."