Methods in the Java interface

Source: Internet
Author: User

The interface can contain variables and methods. However, the variables in the interface are implicitly specified as public static final variables (and can only be public static final variables, which are reported as compilation errors with private adornments), and methods are implicitly specified as public Abstract method and can only be public abstract method (with other keywords, such as private, protected, static, final and so on will be reported compile errors), and the interface of all methods can not have a concrete implementation, that is to say, The methods in the interface must all be abstract methods.

These are all well-known, but what I want to say is:

The invocation of the package allows the abstract methods in the interface to be used directly, such as the methods in the iterator interface, which can be called directly

Collection C1 = new ArrayList ();
C1.add ("123");
C1.add ("456");
C1.add ("789");
Iterator it = C1.iterator ();
while (It.hasnext ();)
System.out.println (It.next ());

This emphasis is placed on the invocation of the package.

Methods in the Java 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.