where static methods are stored in java code example
Example 1: do i have to use static methods in java main
Use a static method
when you want to be able to access the method
without an instance of the class
Example 2: static data and static methods in java
class JavaExample{
private static String str = "BeginnersBook";
static class MyNestedClass{
public void disp() {
System.out.println(str);
}
}
public static void main(String args[])
{
JavaExample.MyNestedClass obj = new JavaExample.MyNestedClass();
obj.disp();
}
}