范围分区_范围

范围分区

Scope refers to the lifetime and accessibility of a variable. How large the scope is depends on where a variable is declared. For example, if a variable is declared at the top of a class then it will accessible to all of the class methods. If it’s declared in a method then it can only be used in that method.

范围是指变量的生存期和可访问性。 作用域有多大取决于变量在何处声明。 例如,如果在类的顶部声明了变量,则所有类方法都可以访问该变量。 如果在方法中声明,则只能在该方法中使用。

For more information, have a look at the Understanding Variable Scope and Using Modifiers With Variables.

有关更多信息,请查看了解变量作用域和将带修饰符的变量一起使用。

Examples:

例子:

For example, the scope of the variable

例如,变量的范围

NUMBER_OF_HOURS_IN_A_DAY is the whole class. Whereas the scope of 
NUMBER_OF_DAYS_IN_A_WEEK is just the 
calculateHoursInWeeks met

public class AllAboutHours{
 private final int NUMBER_OF_HOURS_IN_A_DAY = 24;
 public int calculateHoursInDays(int days)
 {
 return days * NUMBER_OF_HOURS_IN_A_DAY;
 }
 public int calculateHoursInWeeks(int weeks)
 {
 final int NUMBER_OF_DAYS_IN_A_WEEK = 7;
 return weeks * NUMBER_OF_DAYS_IN_A_WEEK * NUMBER_OF_HOURS_IN_A_DAY;
 }
}

翻译自: https://www.thoughtco.com/scope-2034287

范围分区

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值