前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java中请给一个Abstract类实现接口的实例!

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

作者头像
马克java社区
修改2021-03-30 14:21:14
1K0
修改2021-03-30 14:21:14
举报
文章被收录于专栏:java大数据java大数据

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();

        d.close();

    }

}

 

更多请见:https://blog.csdn.net/qq_44639795/article/details/103111035

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档