We turn now to another issue involved in the creation of new objects. In many languages the programmer is allowed to define a special type of function, termed a constructor. A constructor function is implicitly invoked when a new object is created. The body of the constructor can perform whatever actions are necessary in order to make sure that an object is properly initialized.

In C++, Java and C# a constructor is a function with the same name as the class in which it is declared. In Python it is named __init__. In Delphi and Objective-C constructor do not have a special name, but have a different syntax. (In Delphi it is a conveciton to name your constructors create, but this is not a language requirement.)

The example code shows a constructor written in Java.

[audio] [real] Text to accompany slide09, in Chapter 5 of An Introduction to Object-Oriented Programming