1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 7 namespace_08 Inheritance8 {9 class ProgramTen { One Static voidMain (string[] args) A { - //Student s = new Student (); - the //Driver d = new Driver (); -Student s =NewStudent ("Student", -,'male',101); - } - } + - Public class Person + { A Private string_name; at - Public stringName - { - Get{return_name;} - Set{_name =value;} - } in - Private int_age; to + Public int Age - { the Get{return_age;} * Set{_age =value;} $ }Panax Notoginseng - Private Char_gender; the + Public CharGender A { the Get{return_gender;} + Set{_gender =value;} - } $ $ Public voidCHLSS () - { -Console.WriteLine ("eat and drink, sleep ."); the } - Wuyi the - PublicPerson (stringNameintAgeChargender) Wu { - This. Name =name; About This. Age =Age ; $ This. Gender =gender; - } - - //Public Person () A //{ + the //} - $ the } the Public classStudent:person the { the - PublicStudent (stringNameintAgeCharGenderintID) in:Base(name, age, gender) the { the //This . name = name; About //This . Age = age; the //This . Gender = Gender; the This. Id =ID; the } + - the Private int_id;Bayi the Public intId the { - Get{return_id;} - Set{_id =value;} the } the the the - Public voidStudy () the { theConsole.WriteLine ("Student Union Study"); the }94 } the Public classTeacher:P Erson the { the 98 PublicTeacher (stringNameintAgeCharGenderDoublesalary) About:Base(name, age, gender) - {101 This. Salary =salary;102 }103 104 Private Double_salary; the Public DoubleSalary106 {107 Get{return_salary;}108 Set{_salary =value;}109 } the Public voidTeach ()111 { theConsole.WriteLine ("The teacher will give lectures");113 } the } the Public classDriver:person the {117 118 PublicDriver (stringNameintAgeCharGenderintdrivetime)119:Base(name, age, gender) - {121 This. Dirvetime =drivetime;122 }123 124 the Private int_dirvetime;126 Public intDirvetime127 { - Get{return_dirvetime;}129 Set{_dirvetime =value;} the }131 Public voidDrive () the {133Console.WriteLine ("The driver will drive .");134 }135 }136 137 138 139}
An example of inheritance