Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program
- {
- public static void Main()
- {
- IPerson john = new Man("John", 36, true);
- Console.WriteLine(john.GetInfo());
- }
- public interface IPerson
- {
- string Name { get; set; }
- int Age { get; set; }
- string Gender { get; set; }
- }
- public abstract class Person : IPerson
- {
- public Person(string name, int age, string gender)
- {
- this.Name = name;
- this.Age = age;
- this.Gender = gender;
- }
- public string Name { get; set; }
- public int Age { get; set; }
- public string Gender { get; set; }
- public virtual string GetInfo()
- {
- return $"{this.Name}-{this.Age}";
- }
- }
- public class Man : Person
- {
- public Man(string name, int age, bool isBald)
- : base(name, age, "m")
- {
- this.IsBald = isBald;
- }
- public bool IsBald { get; set; }
- public override string GetInfo()
- {
- return $"{base.GetInfo()}-{this.IsBald}";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment