Static Method In Java
Chapter:
Java Basics
Last Updated:
08-08-2016 19:06:58 UTC
Program:
/* ............... START ............... */
public class JavaStaticMethodExample {
public static void main(String[] args) {
welcomeToJava();
print();
}
public static void welcomeToJava() {
System.out.println("Welcome To Java Programming");
}
public static void print() {
welcomeToJava();
welcomeToJava();
}
}
/* ............... END ............... */
Output
Welcome To Java Programming
Welcome To Java Programming
Welcome To Java Programming
Welcome To Java Programming
Notes:
-
It is a method which belongs to the class and not to the object(instance) A static method can access only static data. It can not access non-static data (instance variables).
- Static methods in Java can be called without creating an object of class.
- The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.
- The static variable gets memory only once in class area at the time of class loading.
Tags
Method Example, Java