Static Class

Monkey Forums/Monkey Programming/Static Class

Indiepath(Posted 2011) [#1]
How can I access the methods in a class without having to instanstiate the class?

Example:
Class testClass
  Method test
    Print "test"
  End
End

testClass.test()



Raz(Posted 2011) [#2]
Instead of Method, use Function?


John Galt(Posted 2011) [#3]
Yep, no such thing as a method in an uninstantiated class. The whole point of a method is that it belongs to a specific instance.


Indiepath(Posted 2011) [#4]
Compile Error

Method 'save' cannot be accessed from here.

So I guess you can't do this :
Extern
Class moofooLcst="moofooLcst"
	Function save( key$, data$)
	Method load$( key$ )
	Method remove( key$ )
End
Public

Class lclst Extends moofooLcst
	Method New()
	End
End

lclst.save("test", "test")



Raz(Posted 2011) [#5]

didn't throw up an error for me?


Indiepath(Posted 2011) [#6]
Try it with the "Extern" Statement


Raz(Posted 2011) [#7]
Ahh right, i'll bow out of this then, because im not sure what the Extern stuff is ;)


Indiepath(Posted 2011) [#8]
Yeah I've got a feeling Extern stuff has got to be of type "Method" as it's actually calling a method in an external class and not standalone function :(

Bummer!