Answer:
Constructor Chaining is used to call a constructor in another constructor. Means you can initialize some fields using another constructor in one constructor.
Example:
Public class Example{
string strName;
string strCity;
public Example(string Name, string City)
{
this.strName = FirstName;
this.strCity = City;
}
//another constructor
public Example(string Name):this(Name,"Delhi")
{
this.strName= FName;
}
}
Asked In: Many Interviews |
Alert Moderator