You can create multiple constructors via method overloading.
Each function/method that you create has something called a method signature.
That is an example of a method signature, your compiler reads it as "void myMethod(int)". If you would like to overload this method and create another method with the same name but do something slightly different, you must change it's signature.
This creates a different signature "void myMethod(String)" and is therefore a different function. Depending on what you pass as a parameter into your method when you use it, depends on which method is used. Be careful of typecasting!
Constructors work in the same way, you can create multiple constructors, and using the "this" keyword you can either reference an object the method is a part of, or
call another constructor of the same class.
class myClass {
private:
int setThis;
public:
myClass() { // first constructor calls the second constructor
this(5);
}
myClass(int n) { // second constructor, sets the class variable
setThis = n;
}
}
if you compiled this class and called the following code:
myClass ex = new myClass(5);
// OR
myClass ex2 = new myClass();
the local variable to myClass (named setThis) would be set to 5 in BOTH examples.