There is a lot of articles with clear explanation, you just need to read properly.
Static function is called just by address of the entry point. An instance function, in contrast, is a function with additional hidden parameter called
this
, in some languages
self
. Technically, it is passed exactly as any other parameter, usually first one.
So if you have this:
class MyClass {
public void MyMethod(int parameter) { someField = parameter; }
private int someField;
}
MyClass myVariable;
myVariable.MyMethod(3);
Behind the scene it works exactly like this (pseudo-code!
not real code!):
MyClass.MyMethod(myVariable, 3);
As
myVariable
is passed as a parameter, it provide access to the instance members (like
someField
), same thing about other (non-static methods): they will need this way as well, passed from a calling instance method. That's why you cannot call instance method from static once, without some instance. You can only access other static members (including methods) from static methods.
Naturally, from an instance method you can access all visible members, both static and instance ones.
For a reference, see my other Answer:
What is the Extra Advantage of Delegate[
^] — it's more on delegates but can be useful.
That should resolve your confusion completely, I hope.
—SA