接口练习题(调用接口中的静态方法)

package com.Summer_0427.cn;


interface Info{
    int N = 11;//public static final int N = 11;
    //抽象
    //默认
    default void df() {
        System.out.println("df");
    }
    //不能被 子接口 和 实现类继承的
    public static void sf() {
        System.out.println("sf");
    }
}
class InfoImpl implements Info{
    public void show() {
        System.out.println(N);//继承了父接口中的常量
//        N = 56;//常量不可以修改
        df();//可以被继承过来
        Info.sf();//静态方法的调用,想不创建一个对象直接调用接口的方法,定义成一个静态方法
    }
}
public class TestInfo {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

}

 

posted @ 2019-04-27 22:42  Geek张东坡  阅读(1319)  评论(0编辑  收藏  举报