Java---interface

Source: Internet
Author: User

Interface

Initial understanding Interface interface is a special abstract class with only public abstract methods and global constants in the interface.

1. Define the interface with interface.

2. The format of the members in the interface

public static final int a=1;

public abstract void Show ();

These are the two forms of membership in an interface.

3. If the interface is defined without the static final abstract keyword, the keyword is added to the interface by default.

Attention:

1. Members and methods can only be decorated with public permissions in an interface

2. An interface cannot create an object because it has an abstract method that requires a quilt class implementation, so you have to define all the abstract methods in the subclass to interface so that the class can create objects. If an abstract method is not implemented by the quilt class, the subclass is still an abstract class.

3. Relationship

Relationship between classes and classes: inheriting extends

The relationship between interfaces and classes: implementing implements

The relationship between interfaces and interfaces: inheritance;

4.

There can be a class that implements multiple interfaces between a class and an interface. A class cannot inherit more than one class.

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.