继承和接口现实世界的例子 [英] Inheritance and Interface real world example

查看:219
本文介绍了继承和接口现实世界的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这两者之间的区别是什么,但是我无法使用可以使用接口和继承(超类 - 子类)的真实场景可以使用。

I know what is the difference between the two but I could not come with a real life scenario where Interface can be used and where inheritance(superclass-subclass) can be used.

接口类似于抽象的超类。但是,Interface支持多重继承。但是,如果我不想使用多重继承,那么,在哪里使用什么?

An interface is similar to an abstract Super class. However, Interface support multiple inheritance. But in case i dont want to use multiple inheritance, then, where to use what?

请帮助我。

 

提前致谢。

推荐答案

尝试关联为

接口 - 有关系

继承 - 是一种关系

在realworld中我们举一个CAR类的例子

As in realworld we take an example of a CAR class

汽车继承车辆(任何汽车都是车辆),这意味着车辆的所有属性都将被继承

Car inherits Vehicle (any car is a vehicle) that means all the properties of Vehicle will be inherited

汽车实施导航(界面)

汽车可能有也可能没有导航,如果它实现了它,它将拥有导航的所有功能,否则它就没有。

Car may or may not have a Navigation, if it implements it, it will have all the feature of the Navigation else it wont have.

 

 


这篇关于继承和接口现实世界的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆