Java interface member variables and method default modifiers

Source: Internet
Author: User
In Java's interface, the default modifier for member variables is: public static final

So when we define member variables in the interface, we can

1:public static final String name = "Zhang San";

2:string name = "Zhang San";

Both of the above can be, the old driver is generally the second kind. Since it is a static final variable, it means that you cannot modify the value of this member variable while accessing it outside. Therefore, defining member variables in an interface is generally constant. is not modified. If modifications are to be made, they are defined in the interface-specific implementation class.

Finish the default modifier for the member variable, and by the way, the default modifier for the method, the default modifier for the method is: public abstract

That is, the public abstraction, is used to implement the interface of the class to implement the method. So there are two ways of defining a method in an interface.

1:public abstract list<string> getusernames (Long CompanyID);

2:list<string> getusernames (Long CompanyID);

The same old drivers are the second kind.

Interface is only a higher abstraction of the properties and behaviors of a class of things, and it is an embodiment of the open and closed principle in Java to close the modification.

Java interface member variables and method default modifiers

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.