The differences between Java interfaces, interfaces, classes, and abstract classes

Source: Internet
Author: User
Tags comparable

1. Definition

Java interface is the declaration of a series of methods, is a collection of methods features, an interface only the methods of the characteristics of the method is not implemented, so these methods can be implemented in different places by different classes, and these implementations can have different behavior (function).

2, Java interface and interface differences

Java interface, The structure that exists in the Java language has a specific syntax and structure.

Package Jiekou;public Interface areainterface{double pai=math.pi;double area ();
The above program is the Java interface, is a structure;

Interface, a collection of features of the methods that a class has, is a logical abstraction.

The interface refers to a double area () function.

3. The difference between Java interface and class

Interface implementation and class inheritance rules, in order to secure the data, the inheritance of a class only a direct parent class, that is, single inheritance, but a class can implement multiple interfaces, the interface to compensate for the class cannot inherit the disadvantage, inheritance and interface of the dual design both maintain the class of data security also disguised implementation of multiple inheritance. The Java interface itself has no implementation, because the Java interface does not involve appearances, but only describes the public behavior, so the Java interface is more abstract than the Java abstract class. But the interface is not a class, and you cannot instantiate an interface with the new operator. such as x=new comparable (... );//This is a mistake. However, the interface variable comparable x can be declared; This is permissible.Java interface methods can only be abstract and public, the Java interface cannot haveConstructors, the Java interface can have public,Staticand final properties. That is, the properties in the interface can be defined as public static final int value=5;


The differences between Java interfaces, interfaces, classes, and abstract classes

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.