首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

What’s the difference between a class variable and an instance variable

2012-12-22 
What’s the difference between a class variable and an instance variable??What’s the difference betw

What’s the difference between a class variable and an instance variable?

?

What’s the difference between a class variable and an instance variable?

?

Knowing the terminology is important. Instance variables and class variables are both member variables. They are both member variables because they are both associated with aspecificclass. But, there are differences between instance variables and class variables.

Instance variables

Instance variables belong to an instance of a class. Another way of saying that is instance variables belong to an object, since an object is an instance of a class. Every object has it’s own copy of the instance variables. Here is what a declaration of an instance variable would look like:

Example of an instance variable:

热点排行