简体   繁体   English

从对象继承类

[英]Inheriting class from Object

I've found this declaration in the old project code: 我在旧项目代码中找到了此声明:

public class Protokol:Object

Does it make any sense to inherit class from object? 从对象继承类是否有意义? I am not sure if it was made on purpose or just a dirty code. 我不确定它是故意制作的还是脏代码。

If you don't specify a class to derive from, then you automatically derive from object. 如果您未指定要从中派生的类,则将自动从对象派生。

The code there is just being explicit. 那里的代码只是明确的。 It's not wrong to explicitly derive from object, but it's not necessary to do so either as this is the default. 显式地从对象派生是没有错的 ,但是也不必这样做,因为这是默认的。 Most people choose to omit the : object to keep the code clear. 大多数人选择省略: object以保持代码清晰。

不-每个类都从Object继承-您不必使其明确,但也不会造成伤害-取决于您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM