Skip to main content
Question

Does VC /JVM support static initializers?

  • April 28, 2026
  • 1 reply
  • 9 views

Frank Swarbrick
Forum|alt.badge.img+1

In Java you can define “static initializers”, which are run automatically when the class is initially loaded.  In Java it’s something like this.

public class Test {
static {
// do initialization here.
}
}

Can this be done in Visual COBOL?  I tried googling it, but google AI seems to be returning nonsense.

1 reply

Chris Glazier
Forum|alt.badge.img+4

This can be done by including a static “new” method within the class. This will be run when the class is loaded.

Example:

       program-id. main as "teststatic.main".
data division.
working-storage section.
01 any-key pic x.
01 p procedure-pointer.
procedure division.
set p to entry "teststatic.myclass"
display "in main"
accept any-key

goback.

end program main.

class-id teststatic.myclass public.
working-storage section.
01 any-key pic x static.
method-id new static.
procedure division.
display "in static New".
accept any-key
goback.
end method.

method-id testit.
local-storage section.
01 any-key pic x.
procedure division.
display "in testit".
accept any-key
goback.
end method.
end class.