Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 12, 2007 07:29 AM by mythu
Jun 04, 2007 11:12 AM|LINK
As we know we can create a constructor in abstract class, whts the use of the writeing the constructor in abstract class, as we are not able to create a object of the abstract class, where actually microsoft using this facility.... in c#, pls clerify my
waiting for ur nice reply
Jun 04, 2007 12:41 PM|LINK
The constructor of the abstract class gets called when you create an instance of a class which derives from the abstract class.
Jun 05, 2007 07:30 PM|LINK
in additon to mbischoff in abstract class not only each method are abstract some method can be concrete there (implemented), so to do the require functionality you can use the constructor for some intialization like things.
Jun 06, 2007 10:36 AM|LINK
i have a question.. if the class which derives from the abstract class also has the constructor( of its own) then, will the abstract classe's constuctor be invoked??? as per my knowledge the parent constructor will be invoked only if the child doesnt have
one.correct me if i'm wrong... :)
Jun 06, 2007 02:33 PM|LINK
the constructor of the base class is always called before the constructor of the derived class. E.g. in the following example the comment indicates the order in which the statements are executed:
public abstract class Parent
DateTime d = DateTime.Now; // 2
string a = "hello"; // 3
public class Child : Parent
string b = "asdf"; // 4
static void Main(string args)
Child c = new Child(); // 1
Jun 06, 2007 02:36 PM|LINK
constructor is a default method in each class you need not to define it explicitly, we only use constructor when we have some requirement accordingly , otherwise once you define a class constructor will be by default
just remind how we create object of a class in C#
MyClass identifier = new MyClass(); --- this is the constructor method.
so not only the class constructor each and every base class constructor will get called.
copy paste the following code
i hope it will makes you something more clear.
Jun 12, 2007 07:29 AM|LINK
Thans Martin and vishal