class-id MyClass. working-storage section. 01 volume binary-long private. property-id Volume binary-long. getter. set property-value to volume setter. if property-value < 0 set volume to 0 else set volume to property-value end-if end property. end class.
*> COBOL also allows you to expose fields as properties class-id MyClass. working-storage section. 01 llength binary-long property as "Length". 01 width binary-long property as "Width" no get. 01 breadth binary-long property as "Breadth" no set. end class.
class-id a. method-id main. local-storage section. 01 foo type MyClass value new MyClass. procedure division. add 1 to foo::Volume display foo::Volume end method. end class.
private int _size; private int _length; private int _width; private int _breadth; public int Size { get { return _size; } set { if (value < 0) { _size = 0; } else { _size = value; } } } public int Length { get { return _length; } set { _length = value; } } public int Width { set { _width = value; } } public int Breadth { get { return _breadth; } } foo.Size++;
private int _size = 0; private int _length = 0; private int _width = 0; private int _breadth = 0; public int getSize() { return _size; } public void setSize(int value) { if (value < 0) { _size = 0; } else { _size = value; } } public int getLength() { return _length; } public void setLength(int value) { _size = value; } public void setWidth(int value) { _width = value; } public int getBreadth() { return _breadth; } foo.Size++;
Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.