This might be a dumb question but I had this question hover around me. Is there any difference between class variables and member variables in java or they both one and the same.
class Example {
protected String str;
public static String str1 = "xyz";
}
I know that str1 is a class variable, is str also a class variable?
Yes, the difference is, there is only one per class when we talk about class attributes and there is one per object when we talk about instance attribute.
In your code
protected String strdeclares an instance attribute ( or member variable as you call it ) andpublic static String str1 = "xyz"declares a class attribute.