Top "Constructor" questions

A special type of subroutine called at the creation of an object.

Best way to handle multiple constructors in Java

I've been wondering what the best (i.e. cleanest/safest/most efficient) way of handling multiple constructors in Java is? …

java constructor field
Best way to do multiple constructors in PHP

You can't put two __construct functions with unique argument signatures in a PHP class. I'd like to do this: class …

php constructor multiple-constructors
Using "Object.create" instead of "new"

Javascript 1.9.3 / ECMAScript 5 introduces Object.create, which Douglas Crockford amongst others has been advocating for a long time. How do I …

javascript constructor new-operator object-create
How to inherit constructors?

Imagine a base class with many constructors and a virtual method public class Foo { ... public Foo() {...} public Foo(int i) {...} ... …

c# inheritance constructor
What is the use of static constructors?

Please explain to me the use of static constructor. Why and when would we create a static constructor and is …

c# constructor static-constructor
Constructor of an abstract class in C#

Why is it possible to write constructor for an abstract class in C#? As far as I know we can't …

c# constructor abstract-class
Virtual member call in a constructor

I'm getting a warning from ReSharper about a call to a virtual member from my objects constructor. Why would this …

c# constructor warnings resharper virtual-functions
How to overload __init__ method based on argument type?

Let's say I have a class that has a member called data which is a list. I want to be …

python constructor operator-overloading
Can constructors be async?

I have a project where I'm trying to populate some data in a constructor: public class ViewModel { public ObservableCollection<…

c# constructor async-await
How can I initialize C++ object member variables in the constructor?

I've got a class that has a couple of objects as member variables. I don't want the constructors for these …

c++ constructor class-members object-construction