接口和抽象类之间的关系 [英] relationship betwwen interface and abstract classes

查看:145
本文介绍了接口和抽象类之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抽象类可以继承自接口类吗?我的programme中有8个类.Taxi,Subway和Buss继承自抽象的公共交通工具。还有Taxi和Buss继承自车辆,这是一个接口class.mid-buss和从buss和limo继承的大巴继承自Taxi.i需要说buss和taxi也是抽象类。现在我们有一个从接口继承的抽象类,所以我必须实现Taxi和Buss类中的方法。设计上面的内容是否正确?

解决方案

首先,接口不是类 - 它根本不能包含任何实现。

界面是合同 - 你同意这样做,我会让你进入俱乐部。这不像是一个类,它说我提供这个,你可以建立它。



一个抽象类可以在它的声明中包含一个接口吗?是的。

但它必须在抽象类定义中包含接口属性和方法,或者将它们标记为抽象 - 它不能只是将它们留给具体类来完成。

Can an abstract class inherits from an interface class ?I have 8 classes in my programme.Taxi,Subway and Buss inherit from abstract public transportation.and also Taxi and Buss inherit from vehicle which is an interface class.mid-buss and large-buss inherit from buss and limo inherits from Taxi.i need to say buss and taxi are also abstract classes.now we have an abstract class which inherits from interface so i have to implement the methods in the Taxi and Buss classes. is it correct to design something like above or not ?

解决方案

First off, an interface isn't a class - it can't contain any implementation at all.
An interface is a contract - "You agree to do this, and I'll let you in the club". This is nothing like a class, which says "I provide this, you can build upon it".

Can an abstract class include an interface in it's declaration? Yes.
But it has to include the interface properties and methods in the abstract class definition, or mark them as abstract - it can't just "leave them" to the concrete class to complete.


这篇关于接口和抽象类之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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