Advertisement
karlakmkj

Implementing Interface

Nov 24th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. //In IAutomobile.cs file
  2. using System;
  3.  
  4. namespace LearnInterfaces
  5. {
  6.   interface IAutomobile
  7.   {
  8.     string LicensePlate { get; }
  9.     double Speed { get; }
  10.     int Wheels { get; }
  11.     void Honk();
  12.   }
  13. }
  14.  
  15. ============================================================================================================================
  16. //In Sedan.cs
  17. using System;
  18.  
  19. namespace LearnInterfaces
  20. {
  21.   class Sedan : IAutomobile
  22.   {
  23.     //must include public keyword
  24.     public string LicensePlate { get; }
  25.     public double Speed { get; }
  26.     public int Wheels { get; }
  27.     //define the method
  28.     public void Honk(){
  29.       Console.WriteLine("HONK!");
  30.     }
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement