answersLogoWhite

0


Best Answer

Members which are shared among all instances of a class should be static.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which member should be declared as static?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is members in java?

A member class is a class that is declared as a non-static member of a containing class. If a static member class is analogous to a class field or class method, a member class is analogous to an instance field or instance method.by k7


What is static variable in the class for c plus plus?

Static member variables are local to the class. That is, there is only one instance of a static member variable, regardless of how many objects are instantiated from the class. As such, they must be declared inside the class, and defined outside of the class.


What is the difference between static and nonstatic member with example in java?

It depends on whether the member is a static variable or a static method of the class.A non-static member variable is an instance variable. That is, each instance of the class has its own independent set of instance variables.A static member variable is not associated with any one instance of the class, and exists even when there are no instances of the class. As with all static variables, it exists for the entire duration of the program.A non-static member method is an instance method, thus the method automatically inherits a this pointer.A static member method does not inherit a this pointer, but it does have private access to to the class. Thus specific instances can be passed to a static method if necessary.Static members can be thought of as being common to all instances of a class, rather than a specific instance, even though no instances are actually required in order to make use of them.


What is the difference between static data member and ordinary data member?

Static data is data that does not change from program load to program exit. Static data member do not apply for c. In c++, a static data member is one that is common for all instances of that class.


Why a static data member can be accessed through main?

Static data members are local to the class, not to any instance of the class. That is, you do not need to instantiate an object of the class to access them. They are shared variables, not unlike global variables, the only difference being that that can also be hidden behind static member accessors and/or mutators (get and set methods) of the class. However, a public static data member is a global variable in all but name. Since they do not belong to any instance of the class, they must be initialised outside of the class, and outside of any other code blocks. In other words, they are initialised at compile time and are therefore available at runtime, and can therefore be accessed from the main function if a public interface is implemented or the member is declared public. If it is declared private, the variable is treated as a shared variable that is only accessible to all static members of the class, to all instances of the class and to all friends of the class. If declared protected, it is also accessible to derived classes.

Related questions

What is members in java?

A member class is a class that is declared as a non-static member of a containing class. If a static member class is analogous to a class field or class method, a member class is analogous to an instance field or instance method.by k7


What is static variable in the class for c plus plus?

Static member variables are local to the class. That is, there is only one instance of a static member variable, regardless of how many objects are instantiated from the class. As such, they must be declared inside the class, and defined outside of the class.


Can an abstract method be declared static?

Yes. Abstract methods can be declared static


Is it possible to write in static variables in main method in java?

Short answer: No. Only class member variables may be declared static. Local variables with a static declaration will throw an error (usually "illegal start of expression").


What is static class?

A static class is a class where all the members are declared static.


Can you use this operator to refer static variable?

No. A static member variable is local to the class in which it is declared (much like a global, but scoped to the class) and is accessible to all instances of the class. Since it does not belong to any one instance of the class, it cannot be accessed via the this pointer, as you can with non-static members. Implicitly accessing the variable is the same as explicitly accessing it via ::.Note that it is possible to access a static member variable from outside the class by providing an accessor (getter) for it within the class. The accessor should be static as well, but needn't be, but it should return by value, otherwise it is no better than a global.


What is static variable and how it is declared?

static variables are declared to define a variable as a constant., means if you declare a variable as static the variable becomes costant.syntaxstatic int a=100;this will make the value of a as 100 which is not to be changedWell, no; you think of 'const', which can be used together with static, but not necessarily.Yes you are right bro I was confused it should be const int a=100; then the variable will be a constant.


What is the difference between static and nonstatic member with example in java?

It depends on whether the member is a static variable or a static method of the class.A non-static member variable is an instance variable. That is, each instance of the class has its own independent set of instance variables.A static member variable is not associated with any one instance of the class, and exists even when there are no instances of the class. As with all static variables, it exists for the entire duration of the program.A non-static member method is an instance method, thus the method automatically inherits a this pointer.A static member method does not inherit a this pointer, but it does have private access to to the class. Thus specific instances can be passed to a static method if necessary.Static members can be thought of as being common to all instances of a class, rather than a specific instance, even though no instances are actually required in order to make use of them.


Is a public function accessed like a non-member function?

A public function is scoped to the class in which it is declared. If declared non-static, then it must be invoked against an instance of the class but if declared static then namespace resolution is required to access the function. A non-member function is not scoped to any class but may be scoped to a namespace. If no namespace is specified, then it is scoped to the (unnamed) global namespace. If scoped to any other namespace then namespace resolution is required to access the function.


When do you declare a member as static in java?

You declare a member static whenever the member should be regarded as being local to the class rather than being local to objects of the class. Static members are shared by all instances of the class. Static methods of a class differ from ordinary members in that they do not have an implicit "this" reference, which means they can be invoked even when no instances of the class exist.


What is the difference between static data member and ordinary data member?

Static data is data that does not change from program load to program exit. Static data member do not apply for c. In c++, a static data member is one that is common for all instances of that class.


Why a static data member can be accessed through main?

Static data members are local to the class, not to any instance of the class. That is, you do not need to instantiate an object of the class to access them. They are shared variables, not unlike global variables, the only difference being that that can also be hidden behind static member accessors and/or mutators (get and set methods) of the class. However, a public static data member is a global variable in all but name. Since they do not belong to any instance of the class, they must be initialised outside of the class, and outside of any other code blocks. In other words, they are initialised at compile time and are therefore available at runtime, and can therefore be accessed from the main function if a public interface is implemented or the member is declared public. If it is declared private, the variable is treated as a shared variable that is only accessible to all static members of the class, to all instances of the class and to all friends of the class. If declared protected, it is also accessible to derived classes.