Define constants and use interface

1  Package Penalty for interface1;
 2  / * 
3      interfaces which can be defined member variables, but you must use public static final three keywords can be modified.
4      In effect, this is actually the interface [constant].
5      format:
 . 6      public static final constant data type name = data value;
 7      Note:
 8      once modified final keyword use, instructions can not be changed.
. 9  
10      Note:
 11      1. Among the interfaces constant, may be omitted public static final, Note: this is still not be written.
12      2. among the interface constants must be assigned, it can not be assigned.
13      Name 3. Among the interfaces constants, with full capital letters, use underscores to separate them. (Recommended anonymous rules)
 14   * / 
15  public  interface InterfaceConst {
 16  
17      //This is actually a constant, once the assignment can not be amended 
18 is      public  static  Final  int NUM = 10 ;
 . 19 }
. 1  Package interface1;
 2  
. 3  public  class Demo {
 . 4      public  static  void main (String [] args) {
 . 5          // access interface among constant 
. 6         System.out.println (InterfaceConst.NUM);
 . 7      }
 . 8 }

 

Guess you like

Origin www.cnblogs.com/bingquan1/p/12641328.html