Use of interfaces and methods in C # (Fourteenth Day)

Source: Internet
Author: User
Tags scream

Use of interfaces and methods in C # (Fourteenth Day)
On Friday, I had some time to summarize my daily knowledge, so today I will summarize the commissioned knowledge I learned at Cloud and college on Friday. Theory: interface: • interface Definition: interface keyword, which can contain attributes and methods (not implemented) • The interface name usually starts with "I, for example, IList • If a class inherits the class and implements the interface, the class must be written in front. A class can inherit only one parent class, but multiple interfaces can be implemented. • Class Student: Person, IComparable (this is a defined interface) • a completely abstract Convention • interface is used for implementation • Syntax: [access modifier] interface Interface interface name {// Interface member definition} interface IfFly {void IFly ();} • the Interface only contains the declaration of methods, attributes, indexes, and events, what are the differences between interfaces and classes in public C # by default for all Members: • interfaces cannot be instantiated directly. • The interface does not contain the implementation of methods. • Multiple Interfaces can be inherited, and only one class can be inherited. • The class definition can be split between different source files. • Similarities: • interfaces, classes, and structures can all be inherited from multiple interfaces. • An interface is similar to an abstract base class: any non-Abstract type that inherits an interface must implement all the members of the interface. • Interfaces and classes can contain events, indexers, methods, and attributes. • Not supported between classes and between interfaces. Class is called an implementation interface, not an inheritance interface. The class is father, the interface is capability, and there are multiple capabilities, but not multiple fathers. Class and member modifiers • Class-public, internal, abstract, sealed, static • Member (method) -public, private, protected, internal-protected internal-abstract, virtual, new, override-static methods and instance methods (Definition and call: rubber duck, wood duck, real duck. The three ducks can swim, while the Rubber Duck and the real duck will scream, but the sound is not the same. The Rubber Duck scream, and the real duck scream, but the wooden duck does not. interface implementation. first, define a parent class, Duck, interface, and three subclasses: rubber, wood, and real. The use of methods in the Main function: animal has the methods of eating eat and bark. The methods of dog and cat are different. there is no default implementation in the parent class. You need to use abstract methods. Define the parent class and two child classes according to the question

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.