java中implements是什么意思 java中的implements怎么用?
java中的implements怎么用?Implements是類用來實(shí)現(xiàn)接口的關(guān)鍵字。它用于實(shí)現(xiàn)接口中定義的抽象方法。例如,people是say方法的接口。Public interface peopl
java中的implements怎么用?
Implements是類用來實(shí)現(xiàn)接口的關(guān)鍵字。它用于實(shí)現(xiàn)接口中定義的抽象方法。例如,people是say方法的接口。Public interface people(){Public say()}但是接口沒有方法體。方法體只能通過特定類實(shí)現(xiàn)。例如,類Chinese實(shí)現(xiàn)了接口people。公共類中文實(shí)現(xiàn)peopel{public say(){系統(tǒng)輸出打印(你好!“)}
implements表示實(shí)現(xiàn)接口。
如果在類后使用implements并指定相應(yīng)的接口,則需要在類下實(shí)現(xiàn)相應(yīng)的接口方法。
例如:接口java.lang.com下面定義一個(gè)虛擬方法public int CompareTo(to)
如果一個(gè)類這樣寫
public XXX實(shí)現(xiàn)comparable{
@override
public int CompareTo(to){
]這里是必須實(shí)現(xiàn)的比較方法
}