You might think of static members as "class" members, and non-static members as "instance" members.
A class can be loaded simply by a call to one of its static members, but that (in itself) does not create an instance. Within a static context, there is no guarantee that any instances exist, so non-static (instance) members cannot be referenced.
When we call a non static method from static method, it has to be associated to an object if it's not associated to an object, compiler will throw an error.
consider the example
It will throw an error. if we mark method A declaration as static, the code will compile. the other way is create an instance and call methodA using dot operator.
static methods can be called without instantiating an object of the class they belong to. These methods usually do some general-purpose staff.
MyClass.doSomeThing();
non static methods are methods that usually perform logic on the caller object, you have to instantiate an object then call these methods by object reference
myObject.doSomeThing();
Regards
[ July 13, 2005: Message edited by: Wasim Ayoubi ] [ July 13, 2005: Message edited by: Wasim Ayoubi ]
First, when you post code, please use the Code Tags.
Second, the complete error message gives you a clue what the problem is. "Exception in thread "main" java.lang.NoClassDefFoundError: alpha (wrong name: one/alpha)..."
Because it's in a package, execute this by typing...
java one.alpha
Post by:autobot
Our first order of business must be this tiny ad:
a bit of art, as a gift, the permaculture playing cards