CodesJava

Easy learning with example program codes

what is static method in java?


Static methods

Static methods represent the behavior of whole class. An instance of a class is not required to execute static methods. They can be called using class name.
Syntax: ClassName.methodName

Example

/**
 * This program is used to show that there is no need of an object
 * for accessing a static method. It can be called with class name.
 * @author CodesJava
 */
class Display {
	//static method
	public static void display(){
		System.out.println("Hello codesjava.com");
	}
}
public class StaticExample4 {
	public static void main(String args[]){
		//No need for object to call static method.
		Display.display();
	}
}

Output

Hello codesjava.com


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap