C # abstract (4)

Source: Internet
Author: User

Is there a difference between abstract and ordinary classes? At the time of inheritance, is it possible to inherit only one parent class?

Answer:

abstract classes do not differ from ordinary classes except that they do not implement specific code above abstract methods and properties. Still conform to the basic characteristics of the class. Therefore, in the inheritance of the abstract class also belongs to the base class, that is, only one base class can inherit.

The following code describes the basic characteristics of an abstract class: a reference type.

 Abstract  classHuman { Public Abstract voidThink ();  Public Abstract intAge {Get;Set; }  Public voidShowType (Human Human) = Console.WriteLine ($"this {human. GetType (). FullName}"); }        classIam:human { Public Override intAge {Get;Set ; }  Public Override voidThink () = Console.WriteLine ("The method of the parent abstract class for this implementation"); }    classProgram {Staticiam iam; Static voidMain (string[] args) {iam=NewIam () {age= -};            Showage (IAM);            Changeage (IAM);            Showage (IAM);        Console.readkey (); }       Static voidShowage (iam iam) = Console.WriteLine ($"my age {iam. AGE}"); Static voidChangeage (Human iam) = iam. Age = A;}

C # abstract (4)

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.