December 2003
Beginner
288 pages
7h 8m
English
Constructors are a new concept for people doing structured programming. Constructors do not normally exist in non-OO languages such as C and Basic. Earlier we spoke about special methods that are used to construct objects. In Java, C# and C++, as well as in other OO languages, constructors are methods that share the same name as the class and have no return type. For example, a constructor for the Cabbie class would look like this:
public Cabbie(){
/* code to construct the object */
}
The compiler will recognize that the method name is identical to the class name and consider the method a constructor.
Return Value
Note again that a constructor does not have a return value. If you provide a return value, the compiler will not treat ...
Read now
Unlock full access