Guest User

Untitled

a guest
Feb 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public class Example {
  2.     public static void main(String[] args) { // this method is ALWAYS called by the compiler when the program is run.
  3.         exampleMethod(); // this is a static method so we can call it in a static context.
  4.         Example x = new Example(); // create an instance of the Example class.
  5.         x.exampleMethod2(); // this is a non-static method so we have to invoke it on an object.
  6.     }
  7.     public static void exampleMethod() {
  8.         System.out.println("Static method called."); // print Static method called.
  9.     }
  10.     public void exampleMethod2() {
  11.         System.out.println("Instance method called.");
  12.     }
  13. }
Add Comment
Please, Sign In to add comment