public class MyClass { // This name will dictate the name of your file
public Sting myVariable = ""; // Field or Global variable
public void MyClass() { // Constructor
}
public static void main (String[] args){ // This is the "main" "Method"
MyClass.print("Hello "); // Static method call
MyClass myClass = new MyClass(); // Non-static method call
myClass.print("World");
}
public static void print(String s){ // Static method
System.out.print(s);
}
public void print(String s){ // Non-static method
this.myVariable = s; // Changing the value of a field/global variable
System.out.print(s);
}
}
STATIC METHOD CALL - When you make a static method call you do not make a lasting change to the data inside of the class/object.
NON-STATIC METHOD CALL - For this type of method call you must "instantiate" the object using the Constructor method (which cannot be static). An object can then be passed around. If your method changes the value of a field/global variable in the class then that value remains the same in that object until someone/something else changes it.
When you instantiate an object you can only "invoke" (call) non-static methods inside that object. Likewise you cannot call static methods from an object you must call it by providing the class name followed by a period followed by the method name.
Static methods can only reference other static content. Non-static can reference both.