day10-接口interface-常量的使用
This commit is contained in:
9
day10/src/com/inmind/interface_constant05/Demo05.java
Normal file
9
day10/src/com/inmind/interface_constant05/Demo05.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.inmind.interface_constant05;
|
||||
|
||||
public class Demo05 {
|
||||
public static void main(String[] args) {
|
||||
//调用接口的常量
|
||||
System.out.println(MyInterfaceConstant.age);
|
||||
System.out.println(MyInterfaceConstant.name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.inmind.interface_constant05;
|
||||
/*
|
||||
接口中的常量定义和使用方式:
|
||||
接口中是可以定义“成员变量”,在接口中的“成员变量”其实就是常量,编译器会自动加上一些内容
|
||||
【public static final】 int i = 10;
|
||||
final:最终,被它修饰的内容不能被更改
|
||||
接口常量的作用:为接口的行为规范提供配套的固定值
|
||||
接口名.常量名来调用
|
||||
*/
|
||||
public interface MyInterfaceConstant {
|
||||
public static final int age = 10;
|
||||
String name = "hello";//自动加上【public static final】
|
||||
|
||||
void method();
|
||||
}
|
||||
Reference in New Issue
Block a user