Advertisement
TitanChase

Untitled

May 2nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PersonProgram
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Person p1 = new Person(30000);
  10.             Console.WriteLine("Person Salary: " + p1.Salary);
  11.             p1.Salary = 40000;
  12.             Console.WriteLine("Person Salary: " + p1.Salary);
  13.  
  14.             Student s1 = new Student()
  15.             {
  16.                 PocketMoney = 600
  17.             };
  18.             Console.WriteLine("Student PocketMoney: " + s1.PocketMoney);
  19.             s1.SpendMoney(100);
  20.             Console.WriteLine("Student PocketMoney: " + s1.PocketMoney);
  21.             Console.ReadLine();
  22.  
  23.  
  24.         }
  25.     }
  26.  
  27.     class Person
  28.     {
  29.         private double basicSalary;
  30.  
  31.         public double Salary { get { return basicSalary; } set { basicSalary = value; } }
  32.  
  33.         public Person()
  34.         {
  35.             basicSalary = 2000;
  36.         }
  37.  
  38.         public Person(double Salary)
  39.         {
  40.             basicSalary = Salary;
  41.         }
  42.  
  43.  
  44.     }
  45.  
  46.     class Student : Person
  47.     {
  48.         public double PocketMoney { get; set; }
  49.  
  50.         public void SpendMoney(double Money)
  51.         {
  52.             PocketMoney -= Money;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement