您好,欢迎访问一九零五行业门户网

Java接口的典型案例分享

下面小编就为大家带来一篇java实现接口的典型案例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
废话不多说,直接上代码
package com.car; interface carr{ //汽车名称 string getname(); //获得汽车售价 int getprice(); } class bmw implements carr{ public string getname(){ return "bmw"; } public int getprice(){ return 300000; } } class cheryqq implements carr{ public string getname(){ return "cheryqq"; } public int getprice(){ return 20000; } } public class car { private int money=0; public void sellcar(carr car){ system.out.println("车型:"+car.getname()+"单价:"+car.getprice()); money+=car.getprice(); } public int getmoney(){ return money; } public static void main(string[] args) { car ashop = new car(); ashop.sellcar(new bmw()); ashop.sellcar(new cheryqq()); system.out.println("总收入:"+ashop.getmoney()); } }
以上就是java接口的典型案例分享的详细内容。
其它类似信息

推荐信息