Calling parent class constructor at end of child class constructor?

Posted on 2009-02-19
Last Modified: 2012-05-06
Is it possible to make a class call its parent class' constructor at the END of its constructor, instead of the beginning?

For example, please see the code below.

I hope this makes sense...
public class ParentClass


  public ParentClass()


    //Do parent stuff here



public class ChildClass


  public ChildClass()


    // 1. Do some child stuff here

    // 2. Call parent class constructor now



Open in new window

Question by:JimR123b
    1 Comment
    LVL 19

    Accepted Solution

    No, the base class is automatically instantiated before the derived class. You could have a custom parent class constructor that takes a parameter and does not have the code you wish to delay and call it from the default constructor of the child class, e.g.:

    public class CParent
        public CParent()
            // This default constructor has some code you wish to delay

        public CParent(string sText)

             // This constructor would not have the code the default constructor has

        // Add a function that does what the default constructor would have done

    public  CChild() : base("some value")
        // Here you do some work
        // Now call the parent function that does what the default constructor would have done


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now