实例和继承问题 [英] Instance and Inheritance Question

查看:85
本文介绍了实例和继承问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这并没有太多的背景,但是,在这里(取自

Petzold'用C#编程Windows)片段:


class DatePlus:Date

{

public DatePlus(){}

public DatePlus(int year,int month,int day ):基地(年,月,

天){}

..

..

..

}


我理解DatePlus(){}的默认构造函数。关于第二个,我的问题是

。它是说DatePlus在它的

正式构造函数中接受一年,一个月和一天,但随后立即将它们传递给它继承的基类(日期) ?


谢谢。

解决方案

< ne ****** *****@gmail.com>写道:

我知道这里没有太多的背景,但是,在这里(取自Petzold'的编程Windows与C#)片段:
<类DatePlus:Date
{public DatePlus(){}
public DatePlus(int year,int month,int day):base(year,month,
day) ){}





我理解DatePlus(){}的默认构造函数。我的问题是关于第二个问题。是说DatePlus在其正式构造函数中接受了一年,一个月和一天,但是然后立即将它们传递给它继承自的基类(Date)?




它将它们传递给Date中的base *构造函数*。请注意,

构造函数本身并不是在DatePlus中继承的。


-

Jon Skeet - < sk * **@pobox.com>
http://www.pobox.com/ 〜双向飞碟

如果回复小组,请不要给我发邮件


但是这个:


public DatePlus(int year,int month,int day)


是DatePlus的构造函数,这里没有任何操作,正文是

empty {},因为Date的构造函数(用基数表示)

获取值并用它们做任何事情,对吗?


< ne *** ********@gmail.com>写道:

但是这个:

公共DatePlus(int year,int month,int day)

是DatePlus的构造函数,没有做任何事情在这里,正文是空的{},因为日期的构造函数是(由基数代表)获取价值并用它们做任何事情,对吗?




是的。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


I know this doesn''t have much of a context, but, in this (take from
Petzold''s Programming Windows with C#) snippet:

class DatePlus: Date
{
public DatePlus(){}
public DatePlus(int year, int month, int day): base(year, month,
day){}
..
..
..
}

I understand the default constructor for DatePlus(){}. My question is
about the second one. Is it saying that DatePlus accepts, in its
formal constructor a year, month and day, but then immediately passes
them to the base class that it inherited from (Date)?

Thank you.

解决方案

<ne***********@gmail.com> wrote:

I know this doesn''t have much of a context, but, in this (take from
Petzold''s Programming Windows with C#) snippet:

class DatePlus: Date
{
public DatePlus(){}
public DatePlus(int year, int month, int day): base(year, month,
day){}
.
.
.
}

I understand the default constructor for DatePlus(){}. My question is
about the second one. Is it saying that DatePlus accepts, in its
formal constructor a year, month and day, but then immediately passes
them to the base class that it inherited from (Date)?



It passes them to the base *constructor* in Date. Note that the
constructor itself isn''t inherited in DatePlus.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


But this:

public DatePlus(int year, int month, int day)

is the constructor for DatePlus and nothing is done here, the body is
empty {}, because the constructor for "Date" (represented by base) is
getting the values and doing whatever with them, correct?


<ne***********@gmail.com> wrote:

But this:

public DatePlus(int year, int month, int day)

is the constructor for DatePlus and nothing is done here, the body is
empty {}, because the constructor for "Date" (represented by base) is
getting the values and doing whatever with them, correct?



Yes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于实例和继承问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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