Properties - in COBOL and Java

COBOL Java
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.
// Java's properties are entirely convention based,
// rather than being implemented by the system.
// As a result they exist only as getter and setter methods.

class Properties
{
  private int _size;

  // no equivalent for shorthand properties

  public int getSize()
  {
    return _size;
  }

  public void setSize(int newSize)
  {
    _size = newSize;
  }

  public void static main(String[] args)
  {
    Properties foo = new Properties()
    foo.setSize(foo.getSize() + 1);
    System.out.println(foo.getSize());
  }
}

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.