2 Commits

Author SHA1 Message Date
s-sakiyama
0ac701ce98 8段階目(キャストでサブクラス限定の機能を使おう) 2026-09-16 16:17:23 +09:00
s-sakiyama
08b99dc55b 7段階目(instanceofで型を確認しよう) 2026-09-16 16:07:10 +09:00

View File

@@ -99,19 +99,39 @@ public class Main {
dept[5].setNmDepartment("営業企画部");
allData[10] = dept[5];
int employeeCount = 0;
int deptCount = 0;
for (BaseData data : allData) {
System.out.println(data);
if (data instanceof EmployeeData) {
employeeCount++;
} else if (data instanceof DepartmentData) {
deptCount++;
}
}
System.out.println("社員データ:" + employeeCount + "件\n部署データ:" + deptCount + "件");
System.out.println();
System.out.println("メールアドレス表示");
for (BaseData data : allData) {
if (data instanceof EmployeeData) {
System.out.println(((EmployeeData) data).getMailAddress());
}
}
System.out.println();
//nullおよび前後の空白を取り除いた結果が空文字チェック
// BaseData emp = new EmployeeData("10000", "デフォルト", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
// System.out.println(emp);
// (EmployeeData)emp.setNmEmployee(null);
// System.out.println(emp);
// emp.setNmEmployee("   ");
// System.out.println(emp);
BaseData emp = new EmployeeData("10000", "デフォルト", "ヤマダタツヤ", "yamada@hoge.jp", "aaa", "10");
System.out.println(emp);
((EmployeeData) emp).setNmEmployee(null);
System.out.println(emp);
((EmployeeData) emp).setNmEmployee("   ");
System.out.println(emp);
System.out.println();
System.out.println("コンストラクタに全てから文字で");
BaseData emptyEmployee = new EmployeeData("", "", "", "", "", "");
System.out.println(emptyEmployee);