In java, there is a static variable that is common to all the class members (that is, a single memory segment that is refereed from all the class members. Is there anything similar in c++?
Yes, and they are almost identical to those declared in Java (both in declaration and in the way they behave). For more information regarding static variables in C++, refer to the following article:
What you should have done, and maybe should do in the future, is explain the behavior in Java so that a wider audience can help you. Not all of us are familiar with Java.