Programming Previous page   Next Page

The Stock Constructor Method

The stock constructor creates a stock object from three input arguments:

The constructor must create an asset object from within the stock constructor to be able to specify it as a parent to the stock object. The stock constructor must, therefore, call the asset constructor. The class function, which is called to create the stock object, defines the asset object as the parent.

Keep in mind that the asset object is created in the temporary workspace of the stock constructor function and is stored as a field (.asset) in the stock structure. The stock object inherits the asset fields, but the asset object is not returned to the base workspace.

Constructor Calling Syntax

The stock constructor method can be called in one of three ways:

Otherwise, if none of the above three conditions are met, return an error.

For example, this statement creates a stock object to record the ownership of 100 shares of XYZ corporation stocks with a price per share of 25 dollars.


Previous page  Designing the Stock Class The Stock get Method Next page

© 1994-2005 The MathWorks, Inc.