1public class MyClass {
2
3 void myMethod() {
4 System.out.println("You have called me! My name is: myMethod!");
5 }
6
7 public static void main(String[] args) {
8 new MyClass().myMethod();
9 }
10}
11
1public class methods{
2 public static void main(String[] args){
3 printSum(5, 15); // Print 20
4 }
5 public static void printSum(int a, int b){
6 System.out.println(a + b);
7 }
8 // Our method should be outside the main methods bounds
9 // Call your function inside the main method.
10}
1public class MyClass {
2
3 static void myMethod() {
4 System.out.println("You have called me! My name is: myMethod!");
5 }
6
7 public static void main(String[] args) {
8 myMethod();
9 }
10}
1public class MyClass {
2 static int myMethod(int x) {
3 return 5 + x;
4 }
5
6 public static void main(String[] args) {
7 System.out.println(myMethod(3));
8 }
9}
10// Returns 8