An example of inheritance

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.