The difference between c# interface and java interface
1. Define members in the interface
C#. As shown in the figure, I added a field n to the interface ITest, then vs directly displays a red bottom line, and the error is The interface cannot contain the field
java, as shown below. The compilation also reports an error, but it is not that the interface cannot be included but that the assignment is missing, so let's assign the value and see again. You can see that there is no problem, that is, the member variables are public static final by default. We know that final must be assigned a value, so if it is not assigned, the place will be compiled.
After the assignment, it was found that there was no problem, as shown below:
2. Define some methods in the interface
C#, we all know that the methods in an interface need to be implemented by subclasses, so our methods in the interface cannot be implemented. If an implementation is added, there will be an error. The error is that the interface cannot be defined.
#Java, that is, jdk1.8, has added some methods that can be implemented. It can be implemented in default and static. As shown below, there is no problem compiling. So does c# have default and static methods? In the interface, sorry there are none.
# It is not available in c#. For static, default interface methods cannot be defined. Because it is invalid.
Summary:
1. In java, interfaces can contain fields, but these fields are implicitly static and final, which is not allowed in C# If there are fields in the interface, the compiler will prompt an error when compiling;
2. In Java, method declarations can have public modifiers (even if this is not necessary), but in C#, explicitly It is illegal to specify the public modifier for a method in an interface.
Recommended tutorial: Getting started with java development
The above is the detailed content of The difference between c# interface and java interface. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.