关于课程的问题 [英] question about a class

查看:101
本文介绍了关于课程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于我在一本书上找到的课程的问题

我的问题在于projectionPopulation方法。我想问为什么我们使用count和populationAmount变量。我的意思是,如果我使用年份和人口变量,问题出在哪里?

谢谢!

i want to ask a question about a class i found on a book
my problem is in projectedPopulation method. I want to ask why we use the count and populationAmount variable .I mean where is the problem if i use years and population variables?
thanks !

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号

推荐答案

该方法可能使用了几年而不是引入局部变量计数。但是有一种将方法参数视为常量的惯例。例如,您可能希望使用print语句修改该方法,并使用其中的原始值。无论如何,这不是一个大问题。


另一方面,在这种方法中不使用现场人口是至关重要的。这个方法不应该改变Species对象的状态,对吗?因此,在调用它之后,人口的价值应该是相同的。因此,不要用这种方法触摸它。
That method could have used years instead of introducing the local variable count. But there''s a convention of treating method parameters as though they were constants. For example, you may want to amend the method with a print statement and use the original value of years in it. In any case, this is not a big issue.

On the other hand, not using field population in this method is crucial. This method shouldn''t change the state of the Species object, right? So after calling it, the value of population should be the same. Therefore, don''t touch it in this method.


谢谢@BigDaddyLH。

我是java新手,所以我提出这些问题。


所以我们不会使用年份变量,因为我们可能需要它。我的意思是这不是一个java规则?

第二个我明白了
Thank you @BigDaddyLH.
I am new to java so i make these questions.

So we don''t use the years variable because maybe we need it . I mean this is not a java rule?
The second i understand it



所以我们不要''使用年份变量因为我们可能需要它。我的意思是这不是一个java规则?
So we don''t use the years variable because maybe we need it . I mean this is not a java rule?



这是一种约定,而不是语法规则。要验证这一点,请编辑代码并运行它。

It is a convention and not a rule of syntax. To verify this, edit the code and run it.


这篇关于关于课程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆