Consider a class, say, class A, with one attribute and one method. main() is also inside the class A. Most of us may think since main() is in class A, we can access data members and methods without using an object. But this is not the case. You require an object to access the class members.
public class psvm
System.out.println("hai in display()");
public static void main(String args)
display(); //THIS WILL THROW AN ERROR!
For the above program, you will get an error like...
non-static method display() cannot be referenced from a static context
But if the display method is declared static as
static void display()
then there will not be any error because static members does not require an object for invocation.
Also note keenly that the above program does not have import section but still the above program runs without any error. The reason is that the default package is
The reason why this package is made default is, coding a java program becomes useless without much functionality in java.lang because it is in this package, the basic data types like byte, string, int, thread etc are present. Hence this package is made as default.