---
# System prepended metadata

title: 範例2

---

# 範例2
## 一般印數字
ClassDemo01.java（下稱建構子區）
```java=
public class ClassDemo01 {

	public int getNumber() {
		return new Inner().setNumber() + 100;
	}

	// 內部類別
	private class Inner {
		private int a = 123;

		public int setNumber() {
			return a;
		}
	}
}
```
MainTest.java（下稱測試區）
```java=
public class MainTest {

	@Test
	public void test01() {
		ClassDemo01 cd = new ClassDemo01();
		int z = cd.getNumber();
		System.out.println(z);

	}
}

```
## 輸入一個字元做選擇
建構子區
```java=
public class ClassDemo01 {

	public int getNumber(char x) {
		if (x == 'A') {
			return new Inner().setNumber();
		} else if (x == 'B') {
			return new Inner().setNumber1();
		} else if (x == 'C') {
			return new Inner().setNumber2();
		} else {
			return 0;
		}
	}

	// 內部類別
	private class Inner {
		private int a = 123;

		public int setNumber() {
			return a;
		}

		public int setNumber1() {
			return a + 23;
		}

		public int setNumber2() {
			return a + 100;
		}
	}
}
```
測試區
```java=
public class MainTest {

	@Test
	public void test01() {
		ClassDemo01 cd = new ClassDemo01();
		int z = cd.getNumber('A');
		System.out.println(z);

	}
}
```