1. 程式人生 > >java中請給一個Abstract類實現接口的實例!

java中請給一個Abstract類實現接口的實例!

let source Beginner 方法體 1.2 lan str example not

2.Abstract類實現接口 (視頻下載) (全部書籍)

馬克-to-win:如果實現某接口的類是abstract類,則它可以不實現該接口所有的方法。但其非abstract的子類中必須擁有所有抽象方法的實在的方法體;(當然它abstract爹的也算作是它的)

If a class implements an interface, it must implement all of its methods in the interface, otherwise, this class must be an abstract class. if it is an abstract class, it can leave some methods in the interface unimplemented.refer to the following example.

例1.2---本章源碼
interface OpenClose {
void open();
void close();
}
abstract class Door implements OpenClose {
public void close() {
System.out.println("旋轉把手,拉!");
}
}
/*AdvancedDoorMark_to_win這個類不需要實現close()。因為它已經有close()。它的close()位置在它的超類"Door"。
AdvancedDoorMark_to_win does not need to implement close(), because it already has
close(), the only thing is that the position of its close() is inside its
super class "Door"
*/
class AdvancedDoorMark_to_win extends Door {
public void open() {
System.out.println("旋轉把手,推!");
}

}
public class Test {
public static void main(String args[]) {
AdvancedDoorMark_to_win d = new AdvancedDoorMark_to_win();
d.open();
。。。。。。。。。。。。。。。。。
詳情請進:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner4_web.html#AbstractImplementInterface

java中請給一個Abstract類實現接口的實例!