Your Ad Here

Tuesday, October 28, 2008

Same Name As the Class

There are some unusual aspects of constructor functions. First, it is no accident that they have exactly the same name (Counter in this example) as the class of which they are members. This is one way the compiler knows they are constructors.

Second, no return type is used for constructors. Why not? Since the constructor is called automatically by the system, there’s no program for it to return anything to; a return value wouldn’t make sense. This is the second way the compiler knows they are constructors.

No comments: