Question:
What does it mean that a method or field is “static”?
Answer:
Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That’s how library methods like System.out.println() work. out is a static field in the java.lang.System class. Source: CoolInterview.com
static key word is prefixed with field are method that is not issu in both case the memory is first allocated and aso to break the oops concept rule Source: CoolInterview.com
Answered by: prashant kumar | Date: 10/2/2009
| Contact prashant kumar
Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That?s how library methods like System.out.println() work. out is a static field in the java.lang.System class.
Source: CoolInterview.com
Answered by: Ganesh Sadashiv Chandure | Date: 12/28/2009
| Contact Ganesh Sadashiv Chandure
Static variables and methods are instantiated only once per class. In other words they are class variables, not instance variables. If you change the value of a static variable in a particular object, the value of that variable changes for all instances of that class. Static methods can be referenced with the name of the class rather than the name of a particular object of the class (though that works too). That?s how library methods like System.out.println() work. out is a static field in the java.lang.System class. Source: CoolInterview.com
Answered by: suman | Date: 1/6/2010
| Contact suman
Basically, static methods will be written in an application when user need to do static logic irrespective of the object wise coding. Similarly, static methods will be accessed at class level.
User cannot access the static methods or static variables by using object.
So, we don't have scenario like if one object changes the value of static variable the same will be updated in all other objects :)
And, in contrast to static variables or methods we will have object methods and variables which will be stored in object specific memory and accessed by its own object instance.
Source: CoolInterview.com
Answered by: Venu | Date: 1/10/2010
| Contact Venu
static members are called class members.class members are initialized only once ,at the time the class is loaded in to jvm.class members have only one copy for particular application and same copy used by all instances of that class. Source: CoolInterview.com
Answered by: vinod | Date: 2/24/2010
| Contact vinod
All of the basic, we make the method static when we want to access that method before the class is instantiated. (i.e. calling the method without any object) and so is the main() method static. Source: CoolInterview.com
Answered by: Tejas | Date: 3/4/2010
| Contact Tejas
If a member (ie methods & Fields) is declared as static then those things are belong to Class rather than Instances. You can access these static fields by using Class name.These members are also known as class members. Source: CoolInterview.com
Answered by: Thangaraman Subburaman | Date: 3/8/2010
| Contact Thangaraman Subburaman
The static method or the fields can be instantiated only once per class. Any changes made to the static method will reflect within the scope. More over the the methods or the fields cannot be inherited. Source: CoolInterview.com
Answered by: Manohar | Date: 4/30/2010
| Contact Manohar
static data can be accessed by only static members because this we can access any static member of other class in "public static void main()" function. it is not instance variables or method it can be called by either object of that class or by using that class name. The memory for the static members can be allocated at only ones. Source: CoolInterview.com
Answered by: Shadaf | Date: 8/18/2010
| Contact Shadaf
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|