Objects in Managed COBOL
01 hero type SuperHero value new SuperHero.
01 hero2 type SuperHero.
01 obj object.
01 reader type StreamReader.
01 myLine string.
set hero::Name to SpamMan
set hero::PowerLevel to 3
invoke hero::Defend("Laura Jones")
invoke type SuperHero::Rest *> Calling static method
set hero2 to hero *> Both reference the same object
set hero2::Name to "WormWoman"
display hero::Name *> Prints WormWoman
set hero to null *> Free the object
if hero = null
set hero to new SuperHero
end-if
set obj to new SuperHero
if obj is instance of type SuperHero
display "Is a SuperHero object."
end-if
*> No 'using' construct in COBOL
try
set reader to type File::OpenText("test.txt")
perform until exit
set myLine to reader::ReadLine
if myLine = null
exit perform
end-if
end-perform
finally
if reader not = null
invoke reader::Dispose
end-if
end-try