Java Interface: interface

Source: Internet
Author: User
Tags multiple inheritance in java

Why does Java use interfaces?
    1. There is no support for multiple inheritance in Java, that is, a subclass cannot inherit multiple parent classes, and of course you ask why. Because this causes uncertainty in some methods or variables in subclasses.
    2. In order to compensate for the shortcomings of the single inheritance in [1], Java appeared the concept of interface, the interface can be very good to avoid the emergence of this problem.
    3. In Java, there are many ways to implement interfaces to solve the problem of multiple inheritance between classes.
What is an interface?
    • In the Java programming language, an interface is not a class, but rather a set of requirements descriptions for a class that is defined in accordance with the uniform format of the interface description. An interface has only the characteristics of methods , and there is no implementation of methods , so these methods can have completely different behavior when implemented in different places.
    • A class can implement one or more interfaces.
features of the interface:
    • An interface is not a class, especially an interface that uses the new operator instance.
    • An object that can declare an interface's variables, but cannot construct an interface. (appearing in callback design mode, which embodies the polymorphic nature of Java).
class implements the interface steps:

1) Declare the class to implement the given interface.

2) Define all the methods in the interface.

The keyword that implements the interface is implements:

    

Java Interface: interface

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.