1//Java Program to get the cube of a given number using the static method
2using static before a method or variable we can access it by not creating a
3instance of it.in the program we directly used student.cube(5)
4class Calculate{
5 static int cube(int x){
6 return x*x*x;
7 }
8
9 public static void main(String args[]){
10 int result=Calculate.cube(5);
11 System.out.println(result);
12 }
13}
1Static keyword is used a lot in java.
2 Static means, you
3can access those static variables
4without creating an object,
5just by using a class name.
6This means that only one instance of
7that static member is created which
8is shared across all instances of the class.
9Basically we use static keyword when
10all members share same instance.
1In Java, static keyword is mainly used for memory management.
2It can be used with variables, methods, blocks and nested classes.
3It is a keyword which is used to share the same variable or method of a given
4class. Basically, static is used for a constant variable or a method
5that is same for every instance of a class
1The static keyword in Java is used for memory management mainly. We can apply static keyword with
2variables, methods, blocks and nested classes. The static keyword belongs to the class
3 than an instance of the class.
4
5The static can be:
6
7Variable (also known as a class variable)
8Method (also known as a class method)
9Block
10Nested class
1static keyword is a non-access modifier. static keyword can be used with
2class level variable, block, method and inner class or nested class.
1In the Java programming language, the keyword static indicates that the particular member belongs to a type itself,
2rather than to an instance of that type.
3This means that only one instance of that static member is created which is shared across all instances of the class.