标签:getname 关键字 ber addm 成员 new t member magic 例子
使用:对象引用名 instanceof 类名
作用:来判读引用的对象和类名是否兼容(是否继承该类,或爷爷辈的类)
例子:
Team team = new Team();
team.addMember(new Magicer("jwnming",6));
team.addMember(new Soldier("dogee",4));
team.addMember(new Magicer("wanggl",7));
System.out.print("\n" + "团队成员:");
for(int i = 0;i < team.allRole.length;i++){
if (team.allRole[i] instanceof Role ) {
System.out.print(team.allRole[i].getName() + " ");
}
}
System.out.println("\n" + "\n" +"这个团队的总伤害值:" + team.attackSum());
标签:getname 关键字 ber addm 成员 new t member magic 例子
原文地址:https://www.cnblogs.com/linanana/p/12075310.html