How to call static method?
1)with the help of object or reeference we can call but not recommend
2)with the help of class name
3)without the help of class name(direct call)
Note:
* if static method present in same class. we can call it directly.
* if static method present in different. class the class name is mandatory for. calling static method .
Example :
Class demo
{
public static void call()
{
System.out.println("static variables present ");
}
}
public class staticmethods
{
static void display ()
{
System.out.println("welcome");
}
public static void main(int a)
{
System.out.println(a);
}
public static void main(string args[ ])
{
staticmethods s= new staticmethods();
main(10);
s. display () //calling with object
display (); //direct call
staticmethods.display(); //calling with. class name
demo.call(); //static method present in different class class name should be mandatory
}
}