scopetest.java

来自「实验 1 对象的创建和使用 ( l )理解类的定义; ( 2 )掌握对象的」· Java 代码 · 共 36 行

JAVA
36
字号
//ScopeTest.java
class ScopeTest {
	int x;

	static int m = 0;

	void show() {
		int x = 8, y;
		for (y = 0; y < 2; y++) {
			int v = 5;
			System.out.println("z=" + v);
			v = 10;
			System.out.println("z=" + v);
			System.out.println("方法域中的X=" + x + "在块内显示");
		}
		// z=20;
		System.out.println("方法域中的X=" + x + "在块外显示");
		System.out.println("类域中的X=" + this.x + "在块外显示");
		System.out.println("类域中的m=" + this.m + "在块外显示");
	}

	void setx(int x) {
		this.x = x;
	}

	void setm(int m) {
		this.m = m;
	}

	public static void main(String[] args) {
		ScopeTest application = new ScopeTest();
		application.setx(2);
		application.setm(3);
		application.show();
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?