Java static method : Static « Class « Java

Java static method


public class Main {
  public static void main(String[] args) {
    int result = add(1, 2);
    System.out.println("(1+2) is : " + result);
  public static int add(int first, int second) {
    return first + second;
//(1+2) is : 3


Related examples in the same category

1.Java static member variable example
2.Using Static VariablesUsing Static Variables
3.Static Init Demo
4.Show that you do inherit static fieldsShow that you do inherit static fields
5.Show that you can't have static variables in a method
6.Explicit static initialization with the static clause
7.Static field, constructor and exception
8.This program demonstrates static methods