Defining member variables in the Java interface

Source: Internet
Author: User

The following member variables can be defined in an abstract class:
Public abstract class People {public String name;public int age;public abstract void work ();}

In the people interface below, define the member variable error:

  

the meaning of the interface is understood : the interface can be understood as a unified "protocol", and the interface attribute is also the content of the protocol, but the interface properties are public, static, the final

member features of the interface :
A: Member variables can only be constants. Default modifier public static final
B: The member method can only be an abstract method. Default modifier public abstract

Recommended: Always manually give the modifier.

So the interface definition properties can be written like this:
public interface People {int age=10; String name= "Output name";  //The member variables defined inside the interface are public static final modifier public void eat (); Note: To give the initial value }

  

Defining member variables 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.