Advertisement
pdaogu

Polymorphism

Apr 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Polymorphism
  8. {
  9.     class Window
  10.     {
  11.         protected int top, left, bottom, right;
  12.         public Window (int top, int left, int bottom, int right)
  13.         {
  14.             this.top = top;
  15.             this.left = left;
  16.             this.bottom = bottom;
  17.             this.right = right;
  18.         }
  19.         public virtual void DrawWindow ()
  20.         {
  21.             Console.WriteLine("Window is drawn at (({0}, {1}), ({2}, {3}))", this.top, this.left, this.bottom, this.right);
  22.         }
  23.     }
  24.    
  25.     class Dialog : Window
  26.     {
  27.         public Dialog (int top, int left, int bottom, int right): base(top, left, bottom, right)
  28.         {
  29.  
  30.         }
  31.         public new void DrawWindow ()
  32.         {
  33.             Console.WriteLine("Dialog is drawn at (({0}, {1}), ({2}, {3}))", this.top, this.left, this.bottom, this.right);
  34.         }
  35.     }
  36.     class Program
  37.     {
  38.         static void Main(string[] args) {
  39.             Window d1 = new Dialog(1, 2, 3, 4);
  40.             Dialog d2 = new Dialog(5, 6, 7, 8);
  41.             d1.DrawWindow();
  42.             d2.DrawWindow();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement