Fandom

MoparScape Wiki

Method / Void

13pages on
this wiki
Add New Page
Talk0 Share

This article was featured on the Main Page LinkFA-star
A method or void is a piece of code which can be called upon to:

  • Change a variable
  • Call upon other voids
  • Write to a file
  • Create a new file


Difference between a void and a static void

A static void cannot call upon a specific instance inside the class (e.g. cannot use "this." to refer to something). To clear things up, here is an example:

public class ExampleClass {

public static void StaticExample()
 {
    // static method code
 }
 
 public void InstanceExample()
 {
    // instance method code here
    // can use THIS
 }

}

So, "static" must be put before "void" when using a static void, whereas you only need to put "void" for a normal one.


<source>

// Static method is called -- no instance is involved

ExampleClass.StaticExample(); // Instance method is called

ExampleClass objMyExample = new ExampleClass();

objMyExample.InstanceExample(); </source>

This shows what I mean when I say you cannot use this, etc.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.