in JACK language,how many constructor can we create in one class?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

in JACK language,how many constructor can we create in one class?

nandtwoteris
Constructors may have arbitrary names, but they must return an object of the  class  type.  Therefore  the  type  of  a  constructor  must  always  be  the  name  of  the  class  to  which  itbelongs.
 i quoted this from the book,if constructor must always be the name of the class,so we can only create one constructor in one class ,is that true.
Thanks you
Reply | Threaded
Open this post in threaded view
|

Re: in JACK language,how many constructor can we create in one class?

ashort
You can have more than one constructor in a Jack class.   Sometimes one constructor might take arguments, while another constructor in the same class might be more of a generic default constructor with no arguments, for example.  
Reply | Threaded
Open this post in threaded view
|

Re: in JACK language,how many constructor can we create in one class?

WBahn
Administrator
In reply to this post by nandtwoteris
The key is that the "type" of the constructor must be the name of the class, but the "name" of the constructor can be anything you want.

The 'type' of a function is the data type that is returned by the function. It might be an 'int' or a 'String', for instance. If you have a class named Fred, then any constructor for that class has to return a value of type Fred, but the name of the constructor can be any legal name.