English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

4 answers

U have heard a lot. Now listne from me. It will definitely help u.

Normally to access a class member (variable, method), u need an object of that class. However, it's possible to create a member that can be accessed without reference to a specific instance (object) of the class. To create such a member u declare it with the keyword static.



For the rest see page 141 of "the Complete reference java" J2se 5 Edition, By Herbert Schildt. Name of the topic is "Understanding Static". It is explained there beautifully.

They put static in main method so that it can be called without reference to an instance of the class. Read the above in Schildt and u shall understand.

OK?
Source(s):

Java professional.

2006-10-25 09:02:49 · answer #1 · answered by binaryFusion 5 · 0 0

"A Java(TM) programming language keyword used to define a variable as a class variable. Classes maintain one copy of class variables regardless of how many instances exist of that class. "static" can also be used to define a method as a class method. Class methods are invoked by the class instead of a specific instance, and can only operate on class variables."
{1}

"static variables and methods might better have been called perClass variables and methods. They inherited this misleading terminology from C++. They are the opposite of instance variables and methods that work on a particular object.
There is nothing static (unchanging) about them. They don't cling. They are perfectly clear, unlike radio signals garbled by static.

They are allocated when the class is loaded. static refers to a method or variable that is not attached to a particular object, but rather to the class as a whole. "
{2}

When using static variables or methods, you don't have to create an instance of the class either. This is because these methods and variables do not belong to an instance of the class.

I hope this helps.

2006-10-25 02:59:49 · answer #2 · answered by Instinct_Chick 2 · 0 0

static is nothing but its not an instance member of class. ie.) u can access these members without creating object.
The main() is declared as static because at run time JVM (Java Virtual Machine) Environment will call the method.
Thtas the reason

2006-10-26 13:06:46 · answer #3 · answered by Sudha P 2 · 0 0

from method point of view, static keyword is used prior to those methods which are to be called without any class object. for exp main() method doesnt need any object to be created for the excution.

2006-10-25 03:17:06 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers