There is no such concept as calling an object. You can only call method; well, property too, as reading or assignment can be done via getter or setter methods, respectively.
A method can be a
static method (in some languages called "class method" as it related to the class itself and not to any instance in particular) or
instance method. There is only one difference: instance method require an instance to call, and the body of instance method receives a reference to the instance passed during a call; this reference is passed via a "hidden" parameter called "this".
Now I have to explain the syntax. It's was not nice not to tag the language in the question. How can I explain the syntax? As it's usually C# which is assumed by default for .NET, I'll show it in C#:
The syntax is a bit different, too:
class MyClass {
internal static void ClassMethod() {
}
internal void InstanceMethod() { this.Field = }
int Field;
}
MyClass ClassMethod();
MyClass instance = new MyClass( );
instance.InstanceMethod();
Remaining aspect is access modifiers. By default, access in
private
. The access modifier
internal
(see the sample above) opens up access from any other class, any code placed in the same assembly. This assembly can be references by other assemblies, but they can get access to the methods shown above is
internal
is replaced with
public
.
Note, that access modifiers does not provide any protection (but very helpful to avoid accidental mistakes and isolate parts of code, so it's the best not to "over-publish" anything providing minimal possible access). With Reflection, every member can be accessed regardless access modifier.
A call also can be done with Reflection, but this is quite a different story.
—SA