java * 第八周* 任务【二】接口的练习

来源:互联网 发布:popsub字幕制作软件 编辑:程序博客网 时间:2024/06/06 12:27

2.接口的练习(必做)

(1)封装一类接口ComputerWeight,该接口中有3个功能:double computrWeight,void printName,double printPrice。

(2)封装一类接口ComputerCompany,该接口有2个功能:String computerName,void printFunction。

(3)封装一类对象FlashMemory实现上述两类接口。

(4)用一个程序执行入口Test测试上述对象。

 

 

package hu;public interface ComputerCompany{String computerName();void printFunction();}


 

package hu;publicinterface ComputerWeight{double computrWeight();void printName();double printPrice();}


 

package hu;class FlashMemory implements ComputerWeight,ComputerCompany{public double computrWeight(){    double m=5.5;    return m;}public void printName(){System.out.println( "张三");}public double printPrice(){double p=4.78;return p;}public String computerName(){String s = "LENOvO";return s;}public void printFunction(){System.out.println("FUNCTION");}}


 

package hu;public class Test {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubFlashMemory f = new FlashMemory();System.out.println(f.printPrice());f.printFunction();f.printName();System.out.println(f.computrWeight());System.out.println(f.computerName());}}