Beginners on C # about abstract and interface

Source: Internet
Author: User

Abstraction: Abstract class is an abstraction of a class of objects, and classes that inherit abstract classes and abstract classes belong to the relationship

Interface: interface, can be said to be a specification, inheriting the interface class expression is, I inherited this interface, I can do what

Take a common example: abstract a animal class, horse (horse) inherit animal class, but there is a horse called Tianma, he can fly.

1  Public Abstract classAnimal2 {3      Public voidEatfood ()4     {5         //some code6     }7 }8 9  Public classHorse:animalTen { OneSome code
the } -
public class Flyhorse:horse,iflyable
{
public void Fly ()
{
Some code
}
}
 -  Public Interface iflyable  -  {     void Fly ();  (}

UML diagram:

The virtue method and the abstract method can be defined in abstract, and inherited subclasses can be overridden by overriding the method

Virtue and abstract differ in that abstract cannot implement the principal of a method, and classes that inherit abstract classes must implement abstract methods in abstract classes

The rewriting of the implementation method via virtue and override is the embodiment of C # polymorphism

Beginners on C # about abstract and interface

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.