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