如果我们继承一个类而且我们不能在derrived类中创建对象那么构造函数是否会调用继承类? [英] if we inherit a class and we can not create object in the derrived class then the constructor will be call of inherit class or not?
问题描述
亲爱的所有
昨天我有一份asp.net开发人员的笔试。在这个考试中,我看到一个问题,其中有三个类X,Y,Z和z类继承由Y继承的Y和Y类,代码如下: -
public void class X
{
class X()
{
consol.write( classX);
}
}
public void class Y:X
{
class Y()
{
consol.write(classY);
}
}
public void class Z:Y
{
class Z()
{
consol.write(classZ);
}
}
main()
{
class Z obj = new Z();
}
这个程序的输出是什么?
dear all
yesterday i had a written exam of asp.net developer job. in this exam i saw a question in which there are three classes X,Y,Z and z class inherit by Y and Y class inherit by X. and the code is following:-
public void class X
{
class X()
{
consol.write("classX");
}
}
public void class Y : X
{
class Y()
{
consol.write("classY");
}
}
public void class Z : Y
{
class Z()
{
consol.write("classZ");
}
}
main()
{
class Z obj = new Z();
}
What is the Output of this program?
推荐答案
如果我假设你的代码只是填写错字符,那么输出就是:
classXclassYclassZ
始终首先调用基础构造函数!
If I assume that your code is just full of typos then the output would be:
classXclassYclassZ
The base constructor is always called first!
这篇关于如果我们继承一个类而且我们不能在derrived类中创建对象那么构造函数是否会调用继承类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!