Java interface methods

Source: Internet
Author: User

Java interface methods

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, and a compilation error will be reported when private modification is used ), the method is implicitly specified as a public abstract method and can only be a public abstract method (a compilation error is reported when other keywords such as private, protected, static, and final are used ), in addition, all methods in the interface cannot be implemented. That is to say, methods in the interface must be abstract methods.

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

The call of the package enables the abstract methods in the interface to be used directly. For example, the methods in the Iterator interface 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 ());

The call of the package is emphasized here.

 

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.