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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mark_to_win

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值