德尔福儿童班

发布于 2024-08-15 04:04:37 字数 192 浏览 1 评论 0原文

我认为这是一个愚蠢的问题..但是..当在Delphi中声明另一个类的子类时,子类是否直接获取父类的方法? 解释: 名为“P”的类是名为“C”的类的父类,“P”类有一个名为“Mth”的方法。 是否可以调用“C.Mth”或者我是否注意到“C”声明中的某些内容(可能带有构造函数?)..

问题与变量相同..

我希望足够清楚..谢谢很多回复...

it's a dumb question i think..But.. When a declare a child class of a other class in Delphi, is the childs gets directly the parents methods?
explanations:
A class named 'P' is parent of a class named 'C', the 'P' class has a method called 'Mth'.
Is it possible to call 'C.Mth' or do i notice something in the declaration of 'C' (with the constructor maybe?)..

The question is the same with variables..

I hope to be clear enough.. thanks a lot for responses...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦途 2024-08-22 04:04:37

是的。这就是所谓的“继承”。这意味着父类的所有属性都被子类“继承”。如果您不对子类中的任何内容进行任何更改(覆盖虚拟、添加字段、添加方法等),那么子类的功能将与父类相同。您可以将子类传递给需要父类的其他函数,因为通过继承,子类共享父类的所有品质。

Yes. This is called "inheritance." This means that all the attributes of the parent class are "inherited" by the child class. If you do nothing to change anything in the child class (override virtuals, add fields, add methods, etc...) then the child class would function identically to the parent class. You can pass the child class to other functions that expect the parent class since, by virtue of inheritance, the child shares all the qualities of the parent.

哆兒滾 2024-08-22 04:04:37

子类继承其父类的所有受保护的、公共的和已发布的属性、函数和过程。

它可以直接调用它们,无需任何特殊语法,只要子类没有覆盖它们。

例如:

type
  P = class
  public
    procedure Mth;
  end;

  C = class(P)
  public
    procedure Foo;
  end;

// ... implementation ...

procedure C.Foo;
begin
  Mth; // Calls the P.Mth procedure.
end;

A child class inherits all the protected, public and published properties, functions and procedures of its parent classes.

It can call them directly, without any special syntax, providing the child class has not overridden them.

For example:

type
  P = class
  public
    procedure Mth;
  end;

  C = class(P)
  public
    procedure Foo;
  end;

// ... implementation ...

procedure C.Foo;
begin
  Mth; // Calls the P.Mth procedure.
end;
默嘫て 2024-08-22 04:04:37

是的,您可以调用父方法,就像它们属于子方法一样。这是面向对象层次结构的力量的一部分。

Yeah, you can invoke the parent methods as if they belong to the child. That's part of the power of OO hierarchies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文