Access-Modifer Non-Acess-Modifier static return-type method-name (formal agruments)
P.S.V.M(String[] args){
m1()
}
public static void m1(){
s.o.p("Hello");
}
public void m2(){
m1();
}
class Demo{
P.S.V.M(String[] args){
m1();
demo2.m2()
}
public static void m1(){
s.o.p("Hello");
}
}
class demo2{
public static void m2(){
S.O.P("Code 2 in statc method");
}
}
A static method in Java is a method that belongs to the class itself rather than to any specific instance of the class. This means that static methods can be called without creating an instance of the class. The static keyword is used to declare a static method.
this or super Keyword: Within a static method, you cannot use the keywords this or super, as they refer to instance-specific data.To declare a static method, use the following syntax:
<access_modifier> static <return_type> <method_name>(<parameter_list>) {
*// method body*
}
To call a static method:
<ClassName>.<methodName>(<arguments>);