Java Instance Variables vs Local Variables

后端 未结 10 2088
庸人自扰
庸人自扰 2020-11-30 01:11

I\'m in my first programming class in high school. We\'re doing our end of the first semester project. This project only involves one class, but many methods. My question is

10条回答
  •  执笔经年
    2020-11-30 02:08

    Try to think about your problem in terms of objects. Each class represents a different type of object. Instance variables are the pieces of data that a class needs to remember in order to work, either with itself or with other objects. Local variables should just be used intermediate calculations, data that you don't need to save once you leave the method.

提交回复
热议问题