Previous Topic Next topic Print topic


Properties - in COBOL and Java

Properties in Managed COBOL

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.
Previous Topic Next topic Print topic