In C++, calling foo() from the Base class constructor will call Base.foo()
In C++, one must remember a virtual won't work as expected, as only the method of the current constructed class will be called. The reason is to avoid accessing data members or even methods that do not exist yet.
In Java, calling any method in the constructor could lead to subtle bugs, as the overridden virtual method could try to access a variable which was declared/initialized in the Derived class.
In Java, calling foo() from the Base class constructor will call Derived.foo()
Let's imagine a Base class, with a virtual method foo().
Let's imagine a Derived class, inheriting from Base, who overrides the method foo()
+1 I stumbled upon this on my own... my parents told me about many dangerous things out there but never told me about that, and I had to look it up on the internet.
@Hemant & @Archimedix: Thanks for your comments! The question's author did mention the "virtual thing" in his question, but I guessed the problem was devious/vicious enough to have a developed answer, complete with description, facts and sources, instead of being limited to half a sentence in the question. I'm happy to see I was not wrong about that guess.
Conceptually, the constructors job is to bring the object into existence (which is hardly an ordinary feat). Inside any constructor, the entire object might be only partially formed you can know only that the base-class objects have been initialized, but you cannot know which classes are inherited from you. A dynamically-bound method call, however, reaches forward or outward into the inheritance hierarchy. It calls a method in a derived class. If you do this inside a constructor, you call a method that might manipulate members that havent been initialized yet a sure recipe for disaster.
During base class construction, virtual functions never go down into derived classes. Instead, the object behaves as if it were of the base type. Informally speaking, during base class construction, virtual functions aren't.
In addition to other excellent answers, one thing very important, and usually ignored/forgotten, or misunderstood (which explains why I detail the process below):
The "bugs" for each languages are different:
The difference between C++ and Java is: