Previous Topic Next topic Print topic


Constructors and Destructors - in COBOL and Java

COBOL Java
class-id Heater.
01 _powerLevel binary-long.

method-id new.
    set _powerLevel to 0
end method.

method-id new (powerLevel as binary-long).
    set _powerLevel to powerLevel
end method.

$if JVMGEN set
method-id Finalize override protected.
    *> JVM finalizer method. 
end method.
$else
method-id Finalize override protected.
    *> .NET finalizer method. 
end method.
$end
end class.
public class ConstructorsDestructors
{
    private int _powerOevel;

    public ConstructorsDestructors(int powerLevel)
    {
        _powerOevel = powerLevel;
    }

    @Override
    public void finalize()
    {
        // finalizer code
    }

}

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

Previous Topic Next topic Print topic