search
HomeJavaJavaBaseThe difference between c# interface and java interface

The difference between c# interface and java interface

Nov 19, 2019 pm 02:45 PM
c#javathe differenceinterface

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

The difference between c# interface and java interface

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.

The difference between c# interface and java interface

After the assignment, it was found that there was no problem, as shown below:

The difference between c# interface and java interface

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.

The difference between c# interface and java interface

#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.

The difference between c# interface and java interface

# It is not available in c#. For static, default interface methods cannot be defined. Because it is invalid.

The difference between c# interface and java interface

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

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

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.