static keyword in java meaning code example
Example 1: static in java
using static before a method or variable we can access it by not creating a
instance of it.in the program we directly used student.cube(5)
class Calculate{
static int cube(int x){
return x*x*x;
}
public static void main(String args[]){
int result=Calculate.cube(5);
System.out.println(result);
}
}
Example 2: static keyword in java
public class StaticMethodExample
{
static void print()
{
System.out.println("in static method.");
}
public static void main(String[] args)
{
StaticMethodExample.print();
}
}