Java interface, interface, class, abstract class difference, java Abstract

Source: Internet
Author: User

Java interface, interface, class, abstract class difference, java Abstract

1. Definition

Java interfaces are a series of methods declarations and a set of methods features. An interface has only the features of a method and is not implemented by a method. Therefore, these methods can be implemented by different classes in different places, these implementations can have different behaviors (functions ).

2. Differences between Java interfaces and interfaces

Java interface, the structure in the Java language, with specific syntax and structure.

package jiekou;public interface AreaInterface{double pai=Math.PI;double area();}
The above program is a Java interface, which is a structure;

Interface, a feature set of methods of a class, is a logical abstraction.

The interface refers to the double area (); function.

3. Differences between Java interfaces and Classes

Interface implementation is different from the rule of class inheritance. for data security, when a class is inherited, there is only one direct parent class, that is, single inheritance. However, a class can implement multiple interfaces, interfaces make up for the inability to inherit more classes. The dual Design of inheritance and interfaces not only ensures the data security of classes, but also achieves multi-inheritance in disguise. Java interfaces do not have any implementations, Because Java interfaces do not involve representations and only describe public behaviors. Therefore, Java interfaces are more abstract than Java Abstract classes. However, an interface is not a class and cannot be instantiated using the new operator. For example, x = new comparable (...); // This is incorrect. However, you can declare the interface variable Comparable x; // This is allowed. Java interface methods can only be abstract and public. Java interfaces cannot have constructors. Java interfaces can have public, static, and final attributes. That is, the attribute in the interface can be defined as public static final int value = 5;


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.