java接口開發(fā)代碼 java接口代碼實(shí)例

(Java)誰能給個(gè)“面向接口編程”的例子?

分類: 電腦/網(wǎng)絡(luò) 程序設(shè)計(jì) 其他編程語言

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比漢陰網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式漢陰網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋漢陰地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。

問題描述:

要能在Eclipse下運(yùn)行通過。感激涕零!

解析:

很簡(jiǎn)單啊,我給你一個(gè)java類庫里的接口怎樣啊?是一個(gè)經(jīng)常用到的MouseListener:

/*

* @(#)MouseListener.java 1.17 03/12/19

*

* Copyright 2004 Sun Microsystems, Inc. All rights reserved.

* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.

*/

package java.awt.event;

import java.util.EventListener;

/**

* The listener interface for receiving "interesting" mouse events

* (press, release, click, enter, and exit) on a ponent.

* (To track mouse moves and mouse drags, use the

* codeMouseMotionListener/code.)

* P

* The class that is interested in processing a mouse event

* either implements this interface (and all the methods it

* contains) or extends the abstract codeMouseAdapter/code class

* (overriding only the methods of interest).

* P

* The listener object created from that class is then registered with a

* ponent using the ponent's codeaddMouseListener/code

* method. A mouse event is generated when the mouse is pressed, released

* clicked (pressed and released). A mouse event is also generated when

* the mouse cursor enters or leaves a ponent. When a mouse event

* occurs, the relevant method in the listener object is invoked, and

* the codeMouseEvent/code is passed to it.

*

* @author Carl Quinn

* @version 1.17, 12/19/03

*

* @see MouseAdapter

* @see MouseEvent

* @see a href="java.sun/docs/books/tutorial/post1.0/ui/mouselistener"Tutorial: Writing a Mouse Listener/a

* @see a href="awl/cp/javaseries/jcl1_2"Reference: The Java Class Libraries (update file)/a

*

* @since 1.1

*/

public interface MouseListener extends EventListener {

/**

* Invoked when the mouse button has been clicked (pressed

* and released) on a ponent.

*/

public void mouseClicked(MouseEvent e);

/**

* Invoked when a mouse button has been pressed on a ponent.

*/

public void mousePressed(MouseEvent e);

/**

* Invoked when a mouse button has been released on a ponent.

*/

public void mouseReleased(MouseEvent e);

/**

* Invoked when the mouse enters a ponent.

*/

public void mouseEntered(MouseEvent e);

/**

* Invoked when the mouse exits a ponent.

*/

public void mouseExited(MouseEvent e);

}

接口與類的寫法差不多,這個(gè)接口放在MouseListener.java(稱為一個(gè)編輯單元)里.

java接口編程

//Muitiplication接口

public interface Muitiplication{

double mult(double a, double b);

}

//MuitiplicationImpl實(shí)現(xiàn)類

public class MuitiplicationImpl implements Muitiplication{

public double mult(double a, double b){

return a * b;

}

}

//MuitiplicationImpls實(shí)現(xiàn)類

public class MuitiplicationImpls implements Muitiplication{

public double mult(double a, double b){

return a + b;

}

}

public static void main(args[]){

MuitiplicationImpl m = new MuitiplicationImpl();

System.out.println(m.mult(1.001,1.001));

MuitiplicationImpls ms = new MuitiplicationImpls();

System.out.println(ms.mult(1.001,1.001));

}

java創(chuàng)建接口編程怎么寫代碼

interface Bike{

public void radio();

}

interface Car{

public void tv();

}

interface Dt{

public void music();

}

public class InterfaceDemo implements Bike,Car,Dt{

public void radio() {

System.out.println("可以聽廣播");

}

public void tv() {

System.out.println("可以看電視");

}

public void music() {

System.out.println("可以聽音樂");

}

public static void main(String args[])

{

InterfaceDemo m=new InterfaceDemo();

m.radio();

m.tv();

m.music();

}

}

用java編寫一個(gè)程序用到接口,能用到接口概念的就行

Display.java ? 接口代碼如下:

public?interface?Display?{

public?void?dis();

}

接口的實(shí)現(xiàn)類DisplayImpl.java ? ?代碼如下:

public?class?DisplayImpl?implements?Display?{

@Override

public?void?dis()?{

//?TODO?Auto-generated?method?stub

System.out.println("輸出方法");

}

public?static?void?main(String[]?args)?{

new?DisplayImpl().dis();

}

}

網(wǎng)站標(biāo)題:java接口開發(fā)代碼 java接口代碼實(shí)例
轉(zhuǎn)載源于:http://bm7419.com/article8/ddehiop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作、網(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)

外貿(mào)網(wǎng)站建設(shè)