是否必须在接口中实现所有方法? [英] is compulsory to implement all the methods in interface?

查看:436
本文介绍了是否必须在接口中实现所有方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我.关于..
是否必须在接口中实现所有方法?我在课堂上实现的?对不起,我的英语不好
谢谢

解决方案

是的,除非在直到该类是Abstract类之前,否则必须在实现接口的类中实现所有方法.

让我们变得简单,

您有两种选择:

-实现接口要求的所有方法

-在中声明缺少的方法摘要.这迫使你
声明您的 class 抽象,结果迫使您
子类化之前,先 class ( and 实现缺少的方法)
可以创建任何对象.


是的.它是.您必须至少在类中提供方法存根,才能编译代码.


是否必须问这样的问题?

界面中的每个帮助页面都会对此问题给出答案.
但是,一个棘手的时刻是:如果您的实现类型是class,并且如果该类是从已实现此接口的某个类派生的,则您只能重新实现某些接口成员.

与C ++相比,实现此功能是一个很大的好处,在C ++中,由于缺少此功能,实现COM接口会遇到一些问题.

—SA


hi any body help me . regarding..
is compulsory to implement all the methods in interface? that i implement to my class? sorry for my poor english
thank you

解决方案

Yes, it is mandatory to implement all the methods in a class that implements an interface unless and until that class is an Abstract class.

Let''s Make it Simple,

You have two choices:

- implement every method required by the interface
or
- declare the missing methods abstract in your class. This forces you
to declare your class abstract and, as a result, forces you to
subclass the class (and implement the missing methods) before you
can create any objects.


Yes. It is. You wont be able to compile your code without at least providing the method stub in your class.


Is is compulsory to ask questions like this one?

Each and every help page in interfaces will have an answer to this question.
However, one delicate moment is: if your implementing type is class and if this class is derived from some class where this interface is already implemented, you can re-implement only some of the interface members.

The ability to do this is one great benefit over C++ where implementing COM interfaces is some problem due to lack of this feature.

—SA


这篇关于是否必须在接口中实现所有方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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