. NET Learning notes----2015-07-22 (C # Basics Review 10, object-oriented 2 small exercises)

Source: Internet
Author: User

        Static voidMain (string[] args) {            #regionDefine parent class father (surname LastName, property, Blood type Bloodtype)//sons son class (play game PlayGame method), daughter daughter Class (Dance Dance method),//Call the Parent class constructor (: Base ()) to assign a value to the subclass field//son son = new son ("Zhang San", 10m, "AB", ""); //son.            SayHello (); //son.            PlayGame (); //daughter dh = new daughter ("Zhang Meimei", 100m, "O"); //DH.            SayHello (); //DH. Dance ();            #endregion            #regionDefine Car Class vehicle properties (brand, color), method run//sub-class truck (Truck) Properties weight load, method pull, Sedan (car) Properties passenger passenger quantity, method passengerTruck T=NewTruck ("Dongfeng","Green",Ten); //T.brand = "Dongfeng"; //T.color = "green"; //t.weight = ten;T.sayhello ();            T.lahuo ();            T.run (); Car C=NewCar ("Mercedes","Black",5); //C.brand = "Mercedes-Benz"; //C.color = "BLACK"; //C.passenger = 5;C.sayhello ();            C.zaike ();                        C.run (); #endregionConsole.readkey (); }

First Exercise:
    classFather { Public stringLastName {Get;Set; }  Public decimalProperty {Get;Set; }  Public stringBloodtype {Get;Set; }  PublicFather (stringLastName,decimalPropertystringbloodtype) {             This. LastName =LastName;  This. property =Property ;  This. Bloodtype =Bloodtype; }         Public voidSayHello () {Console.WriteLine ("My name is {0}, I have {1} yuan, I am {2} type of blood", This. LastName, This. property, This.        Bloodtype); }    }
    classSon:father { Public stringName {Get;Set; }  PublicSon (stringLastName,decimalPropertystringBloodtype,stringname):Base(LastName, property, Bloodtype) { This. Name =name; }         Public voidPlayGame () {Console.WriteLine ("son loves to play games"); }    }
    class Daughter:father    {        public daughter (stringdecimalstring  bloodtype)              Base (LastName, property, Bloodtype)        {        }        publicvoid  Dance ()        {            Console.WriteLine ("  daughter loves to dance ");}    }

A second exercise:
/// <summary> ///car's parent class/// </summary> classVehicle {Private string_brand; Public stringBrand {Get{return_brand;} Set{_brand =value;} } Private string_color; Public stringColor {Get{return_color;} Set{_color =value;} } PublicVehicle (stringBrandstringcolor) { This. Brand =brand; This. Color =color; } Public voidRun () {Console.WriteLine ("cars will run ."); } //Public void SayHello ()//{ // //Console.WriteLine ("I am {0} car, I am {1} color", this.) Brand, this. Color); //} Public Virtual voidSayHello () {}}
    classtruck:vehicle {Private int_weight;  Public intWeight {Get{return_weight;} Set{_weight =value;} }         PublicTruck (stringBrandstringColorintweight):Base(brand, color) { This. Weight =weight; }         Public Override voidSayHello () {Console.WriteLine ("I am the {0} card {1} color truck, payload {2} ton", This. Brand, This. Color, This.        Weight); }         Public voidLahuo () {Console.WriteLine ("{0} Big truck can pull a lot of goods oh ~", This.        Brand); }    }
    classcar:vehicle {Private int_passenger;  Public intPassenger {Get{return_passenger;} Set{_passenger =value;} }         PublicCar (stringBrandstringColorintpassenger):Base(brand, color) { This. Passenger =passenger; }         Public Override voidSayHello () {Console.WriteLine ("I am the { 0} card {1} color sedan, the number of passengers is {2} people", This. Brand, This. Color, This.        Passenger); }         Public voidZaike () {Console.WriteLine ("{0} The car sits comfortably and the guests love to sit", This.        Brand); }    }

. NET Learning notes----2015-07-22 (C # Basics Review 10, object-oriented 2 small exercises)

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.