Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Example {
- public static void main(String[] args) { // this method is ALWAYS called by the compiler when the program is run.
- exampleMethod(); // this is a static method so we can call it in a static context.
- Example x = new Example(); // create an instance of the Example class.
- x.exampleMethod2(); // this is a non-static method so we have to invoke it on an object.
- }
- public static void exampleMethod() {
- System.out.println("Static method called."); // print Static method called.
- }
- public void exampleMethod2() {
- System.out.println("Instance method called.");
- }
- }
Add Comment
Please, Sign In to add comment