The Constructor
This takes us to the third lesson in the language trail, Classes and Objects, and the first lesson is a closer look at classes.
The lesson subtly introduces a new concept: That of a "constructor". This term appears neither in the closer look at hello world, nor in the first lesson on classes. But it is not formerly introduced, nor is it explained. We are just told that there is one of them in the bicycle class. Which fact is interesting in itself, because if there is one in the bicycle class, why wasn't it mentioned the last time the bicycle class was set out before us.
It wasn't mentioned because it wasn't there. It wasn't there on the page, and nor was it in the sample class available on a hyperlink. Now I know these are all just illustrative examples, but I really think the learning process for the beginner would be made easier if the sample code for examples given a name, like bicycle, were kept consistent.
As to what the constructor does. Well it seems to assign values to variables/fields. Not quite sure why that can't be done when the variables are declared, but perhaps it will be explained later.
Comments