Advertisement
bero_0401

abstract class

Aug 18th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | Source Code | 0 0
  1.  
  2. namespace CsharpCourse
  3. {
  4.     // abstract class
  5.     public abstract class animal
  6.     {
  7.         public abstract void sound();
  8.  
  9.     }
  10.  
  11.     public class cat : animal // inheritance
  12.     {
  13.         public override void sound() // override the abstract method
  14.         {
  15.             Console.WriteLine("Meow");
  16.         }
  17.  
  18.     }
  19.  
  20.  
  21.     public class dog : animal
  22.     {
  23.  
  24.         public override void sound()
  25.         {
  26.             Console.WriteLine("Hoof");
  27.         }
  28.     }
  29.  
  30.  
  31.     internal class Program
  32.     {
  33.  
  34.  
  35.  
  36.         static void Main(string[] args)
  37.         {
  38.             // animal obj = new animal(); xxx
  39.             animal obj = new cat();
  40.             obj.sound();
  41.  
  42.             obj = new dog();
  43.             obj.sound();
  44.  
  45.         }
  46.  
  47.  
  48.  
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement