โ Back to Interfaces
Question 618
Default Interface Method
Default Interface Method
C# interfaces can provide a DEFAULT method body. Add a default methodGreet()toIGreeterthat returnsHello,+Name()+!, reusing theName()each class supplies. ThePersonclass only implementsName(). Do NOT write aMainmethod. A default interface method is called through an interface reference. For aPersonnamedSamthe program prints: Hello, Sam!
Expected Output:
Hello, Sam!
Topics:
Interfaces
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.