Defining Interfaces
Interfaces define a set of method signatures that specify behavioral contracts for types. Interfaces do not contain data—they define "what to do" rather than "how to do it."
Use the interface keyword to declare an interface, which can contain member functions, operator overloads, and member properties. Interface members have public access level by default, and implementing types must also provide implementations with public.
Interfaces can provide default implementations for their members. If a type implements an interface but does not provide a concrete implementation for a method, the default implementation from the interface is used. This provides flexibility in interface design.
In this example, the Printable interface requires implementing the display() method, while the Named interface provides a default implementation for name() that returns "anonymous". The User class implements both interfaces and provides its own name() method to override the default implementation.
Try removing the name() method from User and observe the use of the interface default value.