Constructor are never called explicitly ?
help me plz.......
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Sep 15, 2014, 11:50 AM EDT
Instead, instance constructors are called in conjunction with the 'new' operator which creates a new instance of the type in question.
If a class or struct has a static constructor, it is called by the runtime once and once only before any instances are created or any static members are referenced.
Within a class an instance constructor can call its base class constructor using the 'base' keyword.
Within a class or struct, it is also possible for one instance constructor to call another using the 'this' keyword. This is known as constructor chaining.
Jignesh TrivediRank #16 · 50.3K reputationPosted Sep 15, 2014, 7:57 PM EDT
If you didn't define a constructor in your class, it will be automatically supplied with the default constructor. But if you defined a constructor with parameters, the supplied default constructor will be removed and you won't be able to use it until you explicitly define it in your class.
you can call base class constructor explicitly using this and base keyword in child class constructor only...
public Test(int data)
: base()
{
}
hope this will help you.