What is static ?how it used?

Showing Answers 1 - 4 of 4 Answers

Guest

  • Nov 27th, 2006
 

Making a variable or method static means they are class members not instance members. A Static member does not get copied as objects are created rather the are shareed among all objects. Static members are initialized at the time class is loaded.

Static members can accssed by classname itself, without any reference to a specific instance.

Methods declared as static have seeveral restrictions: 1)They can only call othr static methods. 2) They must only access static data. 3)They cannot refer to 'this' or 'super' in any way.

You can initialize static members in Static Initialization block.

Static variabls can be used for counting the no. of objects created for a particular class.

main() method is declared static because it is called before we create any instance of the class.

  Was this answer useful?  Yes

ankush6012

  • Aug 20th, 2008
 

Static key word when applied to method or variable this means that the belong to class not any object, you can call them directly.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions