Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
[no name] 30-Mar-13 8:14am    
Why don't you try it out and see for yourself?
Chinmaya C 30-Mar-13 13:36pm    
Hi Ashvin,

how a class can be declared as :

public void class X

is it valid to write void while declaring a class ?

the above program looks incorrect to me. Compile time error.

1 solution

If I assume that your code is just full of typos then the output would be:
classXclassYclassZ

The base constructor is always called first!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900