difference between method and ClassMethod of Class definition


Method() is at the object level (the instance of the class) and ClassMethod() is at the class level .


Lets say that we have a Car class then:

Method PrintCar() {

    //print the car number



ClassMethod PrintAllCars() {

    //for each car call it's PrintCar()


As a consequence of the previous answers it is not allowed to address instance properties using the "dot dot" syntax within a class method. Using the previous example: it is ok to use 

set tCarNumber=..CarNumber 

within the PrintCar() method (providing there is a CarNumber property defined)

but you cannot use it in ClassMethod - as a class method can be called outside of any instance context.

method() is an instance method; you need a car object in order to call it.


set car = ##class(Car).%New()

d car.PrintCar()


ClassMethod() you dont' need an object (provided it's not private).


d ##class(Car).PrintAllCars()

If you know Java, ClassMethod is like a static method; method is like an instance method.