码迷,mamicode.com
首页 > 编程语言 > 详细

java中请给一个Abstract类实现接口的实例!

时间:2018-09-23 22:41:39      阅读:452      评论:0      收藏:0      [点我收藏+]

标签:ref   href   url   style   抽象方法   接口   down   because   nim   

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类实现接口的实例!

标签:ref   href   url   style   抽象方法   接口   down   because   nim   

原文地址:https://www.cnblogs.com/mark-to-win/p/9693646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!