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 Main {
2 public static void main(String args[]) {
3 SayHi();
4
5 int sum = AddNums(5, 6);
6 System.out.println(sum);
7 }
8
9 public static void SayHi() { //This method has no return value
10 System.out.println("Hi!");
11 }
12
13 public static int AddNums(int a, int b) { //This method has a return value
14 return a + b;
15}
1int a = 20;
2int b = 20;
3public static void sum(){ // Void Method
4 System.out.println(a + b);
5}
6public static int sum(){ // Return Function
7 return a + b;
8}