Advertisement
social1986

Untitled

Feb 24th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System;
  2.  
  3. public class Child : Person
  4. {
  5.     public Child(string name, int age)
  6.         : base(name, age)
  7.     {
  8.     }
  9.     public override int Age
  10.     {
  11.         get
  12.         {
  13.             return base.Age;
  14.         }
  15.         set
  16.         {
  17.             if (!ValidateAge(value))
  18.             {
  19.                 throw new ArgumentException("Child's age must be less than 15!");
  20.             }
  21.             base.Age = value;
  22.         }
  23.     }
  24.  
  25.     protected override bool ValidateAge(int age)
  26.     {
  27.         return age < 15;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement