About interfaces and abstract classes

Source: Internet
Author: User
Tags abstract

Abstract class and interface, please refer to the difference between the abstract class and interface, I will not say, then when to select the abstract class, and when to select the interface, OK now I have a situation.

Now I define a person's class, for simplicity's sake, I write briefly, as follows:

public abstract class person

{public

abstract float getweight ();

}

Well, now I have another singer, apparently, he is a man, say inherit, as follows:

Public abstract class Singer:person

{public

abstract void singsong ();

}

Now, I have a dancer, obviously, this is also simple, he is also a person, say inheritance, as follows:

Public abstract class Dancer:person

{public

abstract void Dance ();

}

Now everything is fine, there is no problem, but, another person, he said he will sing, and dance, I call this class for Singerdancer, OK, I'm defining a class,

Public abstract class Singerdancer:singer, dancer

But is that right? C # is not allowed to inherit many, this is not permitted to compile, from another level, this obvious violation of the principle of a single responsibility, then there is no abstract class.

Let's take one more example:

Birds can fly, there is no problem, OK, first define a class first, as follows:

Public abstract class Bird

{public

abstract void Fly ();

}

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.