提交 a0678c6b 编写于 作者: M Mars Liu

add scope

上级 25b967fa
{
"node_id": "569d5e11c4fc5de7844053d9a733c5e8",
"keywords": [],
"keywords": ["常量", "定义", "变量", "final"],
"children": [],
"export": ["solidity.json"]
}
\ No newline at end of file
{
"node_id": "db24c3ffc1f04d9e9a61083364091d82",
"keywords": ["常量", "定义", "作用域"],
"children": [],
"export": ["scope.json"]
}
\ No newline at end of file
{
"type": "code_options",
"author": "刘鑫",
"source": "scope.md",
"exercise_id":"009d35ca11a24baa809d0eeb5e2f66e2"
}
\ No newline at end of file
# 作用域
下面选项中,输出为 100 的是。
## 答案
```java
public class Square {
private int x = 10;
public int area() {
return x * x;
}
}
// place in anywhere runnable
System.out.println(new Square().area())
```
## 选项
### 无法访问到 x
```java
public class Square {
private int x = 10;
}
// place in anywhere runnable
System.out.println(x*x)
```
### x 已经被修改
```java
int x = 10;
x = x * 2;
System.out.println(x*x)
```
### 内部作用域的局部变量从外部无法访问
```java
public void process() {
int x 100;
}
process()
System.out.println(x)
```
### x 值在程序运行的过程中被修改
```java
x = 100;
for(int i = 0; i < 10 ; i++){
x = x + 5;
}
System.out.println(x)
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册