Objective-C 相当于“覆盖"在 C# 中 [英] Objective-C equivalent of "override" in C#

查看:79
本文介绍了Objective-C 相当于“覆盖"在 C# 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设一个 Vehicle 类有一个名为StartEngine"的方法,在我的名为Airplane"的子类中,我想覆盖StartEngine".如果我使用 C#,我应该在 Airplane 的 StartEngine 方法声明/定义中使用override"关键字.

Assume a class Vehicle has a method called "StartEngine", and in my subclass called "Airplane" I want to override "StartEngine". If I use C#, I should use the "override" keyword in Airplane's StartEngine method declaration/definition.

我问的原因是,如果我键入startengine"而不是StartEngine",C# 会抱怨,但由于该关键字,Objective-C 不会.

The reason I am asking, is that if instead of "StartEngine" I type "startengine", C# will complain, but Objective-C won't, thanks to that keyword.

推荐答案

Objective-C 中的所有类和实例方法都是动态调度的,并且可以在子类中覆盖.没有什么像 C# 的 override 关键字,或者像它的 virtual 关键字.

All class and instance methods in Objective-C are dispatched dynamically and can be overridden in subclasses. There is nothing like C#'s override keyword, or like its virtual keyword.

这篇关于Objective-C 相当于“覆盖"在 C# 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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