Parent child relationship
Which constructor fires first in the case of parent child relationship?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Mar 26, 2012, 2:43 AM
First invoke base class constructor and then after derived class constructor
example.
class A
{
public A()
{
}
public A(string d)
{
}
}
class B : A
{
public B(string f) : base(f)
{
}
public B()
{
}
}
when I create
B b =new B("mystring");
first this will call A(String) method and then B(String).
hope this help.
Dipal ChoksiPosted Mar 26, 2012, 12:59 AM
SenthilkumarPosted Mar 26, 2012, 12:57 AM
If you see this example
The base class will be executed first and then super class next.