|NO.Z.00069|——————————|BigDataEnd|——|Java&多态特殊类.V10|——|Java.v10|接口|实际意义|

一、编程代码
package com.yanqi.task09;

public interface Metal {

    // 自定义抽象方法描述发光的行为
    public abstract void shine();
}
二、编程代码
package com.yanqi.task09;

public interface Money {

    // 自定义抽象方法描述购物的行为
    public abstract void buy();
}
三、编程代码
package com.yanqi.task09;

// 使用implements关键字表达实现的关系,支持多实现
public class Gold implements Metal, Money {
    @Override
    public void shine() {
        System.out.println("发出了金黄色的光芒...");
    }

    @Override
    public void buy() {
        System.out.println("买了好多好吃的...");
    }

    public static void main(String[] args) {

        // 1.声明接口类型的引用指向实现类的对象,形成了多态
        Metal mt = new Gold();
        mt.shine();

        Money mn = new Gold();
        mn.buy();
    }
}
四、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=53492:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task09.Gold
发出了金黄色的光芒...
买了好多好吃的...

Process finished with exit code 0

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on 2022-04-03 18:01  yanqi_vip  阅读(9)  评论(0)    收藏  举报

导航