Advertisement
BloodMoonYTC

polimorfizmusperson

Nov 18th, 2021
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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 poliformizmusperson
  8. {
  9.     class Person
  10.     {
  11.         protected string firstName;
  12.         protected string lastName;
  13.         public Person()
  14.         {
  15.         }
  16.  
  17.         public Person(string fn, string ln)
  18.         {
  19.             firstName = fn;
  20.             lastName = ln;
  21.         }
  22.         public void displayFullName()
  23.         {
  24.             Console.WriteLine("{0} {1}", firstName, lastName);
  25.         }
  26.     }
  27.  
  28.     class Employe : Person
  29.     {
  30.         public ushort hireYear;
  31.         public Employe()
  32.             : base()
  33.         {
  34.         }
  35.         public Employe(string fn, string ln)
  36.             : base(fn, ln)
  37.         {
  38.         }
  39.         public Employe(string fn, string ln, ushort hy)
  40.             : base(fn, ln)
  41.         {
  42.             hireYear = hy;
  43.             firstName = fn;
  44.             lastName = ln;
  45.         }
  46.     }
  47.  
  48.     class Program
  49.     {
  50.         static void Main(string[] args)
  51.         {
  52.             Employe me = new Employe("Zsótár", "Csaba", 1983);
  53.             Person Brad = me;
  54.             me.displayFullName();
  55.             Console.WriteLine("Year hired: {0}", me.hireYear);
  56.             Brad.displayFullName();
  57.             Console.ReadKey();
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement