answersLogoWhite

0


Best Answer

Static data members are different from automatic ones in the way that their lifetime is equals to the lifetime of your program. Even if you have declared static members inside of function (class) other than main();

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

A static member of a class is a member that is common (static) amongst all instances of the class. You might, for example, have a static member that counts the number of instances of the class. It would be incremented by the constructor and decremented by the destructor. It would be initizialized by code or convention outside the class interface.

Static members can be used this way to gather statitistics about the class as a whole or, alternatively, they can be used in class specific ways, such as in a class allocator that is optimized for the class.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

STATIC DATA MEMBER

A data member of a class can be qualified as static. The properties of a static member variable are similar to that of a static variable. A static member variable has certain special characeristics.

1) It is initialized to 0(zero) when the first object of this class is created. No other initialization is permitted.

2) Only one copy of that member is created for the entire class and is shared by all the objects of that class, No matter how many objects are created.

3) It is visible only within the class but its lifetime is in the entire program.

The type and scope of each static member variable must be defined outside the class definition.This is necessary because the ststic data member are stored separately rather than as a part of an object. Since they are associated with the class itself rather than with any object. They are also known as class variable.

DATA MEMBER

Data memeber is the simple variable of a class which is initialized by member function of same class. By default data member is private and external functions can not access it.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A non static class member is an ordinary class member that is part of a class instance.

A static class member is shared by all instances of the class, i.e. there is only one copy, its lifespan starts from the first instance creation until the end of the program execution, and it can only be accessed by static class methods. One common use of static class members is to count the number of instances of a class there are, another might be to manage a private memory allocation strategy for the class.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

A static member is local to the class rather than to an object of the class.

A static class is a class that cannot be instantiated. All members of a static class must be declared static and there can be no constructors, no copy or move operators and no destructor.

There is no such thing as a static constructor per se. However, you can define a static method that constructs and returns an object of the class. Like so:

struct A {

static A* construct () { return new A; }

};

int main() {

A* x = A::construct(); // invoke static constructor

// ...

delete x;

x = nullptr;

}

Clearly, a "static constructor" serves no practical purpose and would only lead to confusion.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Static contents belong to the whole class and not for the instances. Static members can access without instantiating. Members that are not static can be considered as dynamic members.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between static and non static class members in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is static class?

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


Are the methods or members of static class static?

A static class may or may not have static members. Adding the static keyword to the class definition won't change this. Note that an inner class which is not static may not contain static members (unless those members are also declared final).


How you declare class scoped variables and member functions?

To scope class members to the class (rather than to instances of the class), declare them as static members of the class. Static members are accessible even when no instances of the class exist. As such, static member functions do not have access to a 'this' pointer, unlike ordinary (nonstatic) member functions.


Difference between static and non static constructor?

A static constructor is used to do anything you need done before any static methods are called such as static variable initialization. In Java (as in C#) when a static constructor is called is non-deterministic but will always be called before a static method on the same class.


What do you understand by static members?

Static members are local to the class in which they are declared. Unlike instance members (non-static members), they are not associated with any one instance of the class, and are available (access permitting) even when no instance of the class exists. They can be thought of as being global functions and variables, but with a much more refined scope.


What was the main difference between members of the middle class and members of the lower class?

Access to education, often laws were overlooked by the bourgoisie


What is a static data linkage?

Static data members of a class in namespace scope have external linkage. Static data members follow the usual class access rules, except that they can be initialized in file scope. Static data members and their initializers can access other static private and protected members of their class. The initializer for a static data member is in the scope of the class declaring the member. A static data member can be of any type except for void or void qualified with const or volatile. The declaration of a static data member in the member list of a class is not a definition. The definition of a static data member is equivalent to an external variable definition. You must define the static member outside of the class declaration in namespace scope.


Why is it not advisable to use this pointer with static members?

It is not inadvisable, it is impossible. Static member methods do not have access to a this pointer since they are not associated with any instance. Static members are scoped to the class, not to an object (an instance of the class). Only instance members have access to the this pointer.


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 kinds of members can a class have?

Members of a class may include 1. Static Methods 2. non-static methods 3. Instance variables 4. Sub classes etc.


Can Static data members be declared either in the private or public section of class declaration?

Yes. Static members can be private or public. (Or protected.)


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.