diff --git a/day10/src/com/inmind/interface_constant05/Demo05.java b/day10/src/com/inmind/interface_constant05/Demo05.java new file mode 100644 index 0000000..83ae77c --- /dev/null +++ b/day10/src/com/inmind/interface_constant05/Demo05.java @@ -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); + } +} diff --git a/day10/src/com/inmind/interface_constant05/MyInterfaceConstant.java b/day10/src/com/inmind/interface_constant05/MyInterfaceConstant.java new file mode 100644 index 0000000..73bc16c --- /dev/null +++ b/day10/src/com/inmind/interface_constant05/MyInterfaceConstant.java @@ -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(); +}