Display implementation interface and implicit implementation interface differences

Source: Internet
Author: User

Define an interface first:

Public Interface ICategory

{

String GetName ();

}

Then implement the interface defined above:

public class Category:icategory

{

public string GetName ()

{

return name;

}

}

The above approach is to implicitly implement the interface (the default is to use an implicit interface)

Explicitly implement the interface mode:

public class Category:icategory

{

public string Icategory.getname ()

{

return name;

}

}

Difference:

1. When implementing an interface implicitly, we have two ways to invoke the method that implements the interface (GetName ()), namely:

ICategory category=new category ();

Category. GetName ();

And

Category category=new category ();

Categoty. GetName ();

2. When explicitly implementing an interface, we have only one way to invoke GetName (), namely:


ICategory category=new category ();

Category. GetName ();

Conclusion:

1. When an interface is implicitly implemented, the interface and class (the class that implements the interface) can access the methods in the class;

2. When an interface is explicitly implemented, only the methods in the class are accessed through the interface;

Explicit Advantages:

1. Hiding the implementation code of the class implementing the interface

Display implementation interface and implicit implementation interface differences

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.