A constructor is a function that is implicitly invoked when
a new object is created. The constructor performs whatever actions are
necessary in order to initialize the object.
- In C++, Java, C# a constructor is a function with the same name
as the class.
- In Python constructors are all named __init__
- In Delphi, Objective-C, constructors have special syntax,
but can be named anything. (Naming your constructors create is a
common convention).
class PlayingCard { // a Java constructor
public PlayingCard (int s, int r) {
suit = s;
rank = r;
faceUp = true;
}
...
}