wingman007

OOP_20151b_Inheritance_Person

Mar 21st, 2015
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 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 Person1b
  8. {
  9.     class Person : Introducable
  10.     {
  11.         protected string name;
  12.         protected int age;
  13.         public static int counter = 0;
  14.         public static string nationality = "Bulgarian";
  15.  
  16.         public string Name
  17.         {
  18.             get { return name; }
  19.             set { name = value; }
  20.         }
  21.  
  22.         public int Age
  23.         {
  24.             get { return age; }
  25.             set { age = value; }
  26.         }
  27.  
  28.  
  29.         // working horse!!!
  30.         public Person(string name, int age)
  31.         {
  32.             this.name = name;
  33.             this.age = age;
  34.             counter++;
  35.         }
  36.  
  37.         public Person()
  38.             :this("Default", 0)
  39.         {
  40.             // this.name = "Deafult";
  41.             // this.age = 0;
  42.         }
  43.  
  44.         public Person(int age, string name)
  45.             : this(name, age)
  46.         {
  47.             // this.name = name;
  48.             // this.age = age;
  49.         }
  50.  
  51.         public virtual void IntroduceYourSelf()
  52.         {
  53.             Console.WriteLine("My name is {0}!. I am {1} years old! I am {2}",
  54.                 name, age, nationality);
  55.         }
  56.  
  57.         /*
  58.         public string GetName()
  59.         {
  60.             return name;
  61.         }
  62.         public void SetName(string name)
  63.         {
  64.             this.name = name;
  65.         }
  66.  
  67.         public int GetAge()
  68.         {
  69.             return age;
  70.         }
  71.         public void SetAge(int age)
  72.         {
  73.             this.age = age;
  74.         }
  75.         */
  76.     }
  77. }
Add Comment
Please, Sign In to add comment