in C++ calling virtual method from within base class ctor will never call derived override.
in Java it does.
How about C#? (Don’t have visual studio installed ATM)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it does in C# – the object is of its “final type” even while it’s being constructed.
Just like in Java, this is a bad idea and should be avoided wherever possible, as you may be calling methods implemented at an inheritance “level” which hasn’t been fully initialized yet for that object.
One difference in execution order between Java and C# is that in C#, instance variables with initializers, like this:
… and initialized before the base class constructor executes, whereas in Java they’re effectively executed just before the main body of the subclass constructor, after the superclass constructor executes.