____________________________________________________________________
class StaticDemo
{
static String name = "static"; // static variable
static void show()
{
System.out.println("This is comes from static method");
}
public static void main(String []args)
{
System.out.println(name);
show(); // here we calling show method
}
}
in the above simple program we can access the variables and methods without Object.
If you declare member as static directly we can call the variables or methods if they are in the same class
____________________________________________________________________________
if you are using different classes we may use follows.
class Other
{
static void show()
{
System.out.println("other class");
}
}
class OtherDemo
{
public static void main()
{
show(); /// error
Other.show();
}
}
In this example we cannot call show() method. because it is in other class. so only you can access classname.membername(Other.show())
without creation of an Object we can access the members(variables & methods) of that class.
if any doubt/mistakes please mail to
ilanji83@gmail.com