Possible Duplicate:
non-static variable cannot be referenced from a static context (java)
public class DemoJava {
public class Hello {
void fun()
{
System.out.println("This is static fun man!!");
}
}
public static void main(String[] args) {
Hello hello = new Hello();
hello.fun();
}
}
In this example it will give me an error since I am trying to access a non-static class from a static method. Fine. For instance, if I have the same Hello
class in another file and I do the same thing it does not give me an error.
Even in that case we are trying to access non-static class from static method. But that doesn't give any error. Why?