Java Foundation-java differs from C # interface.

Source: Internet
Author: User
1. Define members in the interface

C #, I added a field N to interface ITest, then vs directly shows the red bottom line, and the error is that the interface cannot contain fields

Java, for example, the compilation is also an error but not the interface can not be included but the assignment is missing, then we will be assigned to look at the value. You can see that there is no problem, that is, the member variable defaults to public static final, we know that final must be assigned, so no assignment will compile the premises.

  

After assignment, it is found that there are no problems, such as.

    

2, the interface defines some methods

C #, we all know that the methods in an interface need subclasses to implement, then our methods in the interface can not be implemented, if the implementation is added there will be errors. The error is that the interface cannot be defined.

    

Java, or jdk1.8, adds some methods that can be implemented. It can be implemented in default,static. For example, the compilation is not a problem. So does C # have a default and static method? In the interface, I'm sorry No.

    

There is no in C #, and the interface method for Static,default is undefined. Because it is invalid.

    

Summarize

Simple two points different, like other exchanges together.

Java Foundation-java differs from C # 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.