day10-接口的常量定义和使用

This commit is contained in:
2026-07-27 11:10:34 +08:00
parent dc3b2c4609
commit 782e9f2658
2 changed files with 22 additions and 0 deletions
@@ -0,0 +1,8 @@
package com.inmind.interface_constatnt05;
public class Demo05 {
public static void main(String[] args) {
System.out.println(MyInterface.i);
//MyInterface.i = 100;
}
}
@@ -0,0 +1,14 @@
package com.inmind.interface_constatnt05;
/*
接口中的常量定义和使用方式:
接口中是可以定义“成员变量”,在接口中的“成员变量”其实就是常量,编译器会自动加上一些内容
【public static final】 int i = 10;
final:最终,被它修饰的内容不能被更改
接口常量的作用:为接口的行为规范提供配套的固定值
接口名.常量名来调用
*/
public interface MyInterface {
public static final int i = 10;//常量
int j = 10;//与上方是一致的!!!
}