接口練習題(調用接口中的靜態方法)


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

    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM