Back to Developer Roadmap

trait

src/data/roadmaps/scala/content/[email protected]

4.0771 B
Original Source

trait

A trait is a type that defines a contract of fields and methods, which can be either abstract (unimplemented) or concrete (implemented). Traits are used to share behavior across classes, enabling code reuse without relying on single inheritance. Traits are similar to Java 8’s interfaces. Classes and objects can extend traits using the extends keyword, but traits cannot be instantiated and therefore have no parameters.

Visit the following resources to learn more: