Sunday, March 29, 2015

What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?

Question:What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)??

Answer: </P><P align=justify>The syntax for calling another constructor is as follows: </P><P align=justify>class B</P><P align=justify>{</P><P align=justify>B(int i)</P><P align=justify>{ }</P><P align=justify>}</P><P align=justify></P><P align=justify>class C : B</P><P align=justify>{</P><P align=justify>C() : base(5) // call base constructor B(5)</P><P align=justify>{ }</P><P align=justify></P><P align=justify>C(int i) : this() // call C()</P><P align=justify>{ }</P><P align=justify></P><P align=justify>public static void Main() {}</P><P align=justify>}

Tags:Interview Questions, Microsoft, C#,

Please submit your Interview Answer for the above Question via replying to this post. Thank you for visiting to our blog, Have a Good Day!.



Sponsor Advertisement



Human Resource Management Software

Human Resource Management Software

Powerful, configurable software for human resources management that is easy to manage and remarkably cost-effective, whatever the size of your company. Now there’s a smarter, more efficient way to handle all of your people-related activities. Easy-to-use system manages the full hire-to-retire lifecycle...

No comments:

Post a Comment