Files
javaSE-0113/day10/src/com/inmind/interface_constant05/Demo05.java

26 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.interface_constant05;
/*
接口中的内容特点:
1.抽象方法jdk7之前制定规则规范
2.默认方法jdk8优化解决接口升级的问题
3.静态方法jdk8:定义一些可以直接通过接口名调用的方法
4.私有方法jdk9对默认方法和静态方法共有的代码进行抽取复用并不让外界调用
5.常量jdk7之前定义一些可以通过接口名直接访问的值
抽象方法:定义实现类必须遵守的规范;
默认方法:为实现类提供可选的默认实现;
静态方法:为接口本身提供辅助工具功能
私有方法jdk9对默认方法和静态方法共有的代码进行抽取复用并不让外界调用
接口常量的作用域是全局可见public且不可修改final适合定义"公共标准值"。为接口的行为规范提供配套的固定值
*/
public class Demo05 {
public static void main(String[] args) {
//调用指定接口的常量
//MyInterface.i = 100;//接口中的变量其实是常量,不可更改的!!!
//MyInterface.j = 200;
System.out.println(MyInterface.i);
System.out.println(MyInterface.j);
}
}