C #. net interface 2

Source: Internet
Author: User
/*
* Created by sharpdevelop.
* User: noo
* Date: 2009-8-16
* Time: 17: 35
*
* Interface 2 (explicitly and implicitly execute interface members)
*
* Class implicitly executes interface members (interface members can be accessed through class and interface objects)
* Explicitly execute interface members (interface members can only be accessed through interface objects)
*
*/

Using system;
Interface imyinterface
{
Void output1 ();
Void output2 ();
}
Class myclass: imyinterface
{
Public void output1 () // This method indicates that the member function can be accessed through a class or interface object.
{
Console. writeline ("implicit invocation interface member ");
}
Void imyinterface. output2 () // Note: Public, private, protected, and other modifiers cannot be added before. This method indicates that only interface objects can be used for access.
{
Console. writeline ("explicitly executing interface members ");
}
}
Class Test
{
Static void main ()
{
Imyinterface A = new myclass ();
A. output1 ();
A. output2 ();
// A can execute two interface members: output1 and output2.

Myclass B = new myclass ();
B. output1 ();
// The output2 interface member cannot be executed in B.
}
}

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.