Answer Posted / madhu
In C++ when you declare and define a static variable, it
tells the compiler that only one copy of memory will be
allocated and all the objects of that class will share that
copy.
As we know for class data variables memory will be created
independently for every object of that class. and we can
access the data using object. But, for static variables
memory is created only once for all objects and is no object
is owned the static variable. we can access the static
variable using class name.
Mainly static variables are used when want to count the
objects created and destroyed and when we are dealing with
singleton design pattern.
| Is This Answer Correct ? | 10 Yes | 0 No |
Post New Answer View All Answers
What is overriding in oop?
Write a program to reverse a string using recursive function?
what's the basic's in dot net
write a program to find 2 power of a 5digit number with out using big int and exponent ?
Can bst contain duplicates?
Is this job good for future? can do this job post grduate student?
What is polymorphism used for?
Describe these concepts: Polymorphism, Inheritance and Abstraction.
What is overriding vs overloading?
What are different oops concepts?
How do you use inheritance in unity?
What is the difference between encapsulation and polymorphism?
When not to use object oriented programming?
What is encapsulation and abstraction? How are they implemented in C++?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?