![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
You'll now build a new Product class with getter and setter methods and create an object from the Product class.
id
, prodName
, and description
:
function Product (id:Number, prodName:String, description:String) {}
setID(id); setProdName(prodName); setDescription(description);
class
keyword. Be sure to declare each variable used in the class:
class Product { var id:Number; var prodName:String; var description:String function Product (id:Number. prodName:String, description:String) { setID(id); setProdName(prodName); setDescription(description); } }
Void
as the return type for the setter methods, and indicate the data type returned for the getter methods.
class Product { var id:Number; var prodName:String; var description:String function Product (id:Number, prodName:String, description:String) { setID(id); setProdName(prodName); setDescription(description); } public function setID (id:Number) :Void { this.id = id; } public function setProdName (prodName:String) :Void { this.prodName = prodName; } public function setDescription (description:String) :Void { this.description = description; } public function getID () :Number { return id; } public function getProdName () :String { return prodName } public function getDescription () :String { return description; } }
Note: An example finished file of the file you just created, named Product.as, is located in your finished files folder. For the path, see Set up your workspace.
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |