java中的interface接口實(shí)例詳解-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)公司基于分布式IDC數(shù)據(jù)中心構(gòu)建的平臺(tái)為眾多戶提供四川雅安服務(wù)器托管 四川大帶寬租用 成都機(jī)柜租用 成都服務(wù)器租用。

 java中的interface接口實(shí)例詳解

接口:Java接口是一些方法表征的集合,但是卻不會(huì)在接口里實(shí)現(xiàn)具體的方法。

java接口的特點(diǎn)如下:

1、java接口不能被實(shí)例化
2、java接口中聲明的成員自動(dòng)被設(shè)置為public,所以不存在private成員
3、java接口中不能出現(xiàn)方法的具體實(shí)現(xiàn)。
4、實(shí)現(xiàn)某個(gè)接口就必須要實(shí)現(xiàn)里面定義的所有方法。

接下來看一個(gè)實(shí)現(xiàn)接口的案例:

 



package hello;   interface competer{ //定義接口 void set_compt(int com); void print_compt_information(); } class bj implements competer{ //接口實(shí)現(xiàn) int com ; public void set_compt(int com) { this.com = com ; // System.out.println("端口" + com); } public void print_compt_information() { System.out.println("端口" + com); System.out.println("筆記本"); } } class taishi implements competer{ int com ; public void set_compt(int com) { this.com = com ; //System.out.println("端口" + com); } public void print_compt_information() { System.out.println("端口" + com); System.out.println("臺(tái)式機(jī)"); } } public class inter { public static void main(String[] args) { taishi com = new taishi(); bj bjj = new bj(); com.set_compt(100); bjj.set_compt(120); com.print_compt_information(); bjj.print_compt_information(); } }

當(dāng)前標(biāo)題:java中的interface接口實(shí)例詳解-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://muchs.cn/article8/dpship.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作網(wǎng)站導(dǎo)航、動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)