必须创建一个使用 SuperHero 类的程序,该类使用名称类和日期类。在主代码中,将属性分配给英雄对象时收到错误。
public class JavaProgram{
public static void main (String [] args){
Date [] birthDay = new Date [3];
Name [] name = new Name [3];
SuperHero [] hero = new SuperHero [3];
for (int i = 0; i < hero.length; i++){
birthDay[i] = new Date();
name[i] = new Name();
hero[i] = new SuperHero();
}
birthDay[1].setDate(10,10,87);
birthDay[2].setDate(5,10,99);
birthDay[3].setDate(3,12,79);
name[1].setName("Michael");
name[2].setName("Scott");
name[3].setName("Jim");
SuperHero hero [1] = new SuperHero(name[1], "Suit", "Cape", "Flying", birthDay[1] );
SuperHero hero [2] = new SuperHero(name[2], "Suit", "No Cape", "Flying", birthDay[2] );
SuperHero hero [3] = new SuperHero(name[3], "Suit", "Cape", "Flying", birthDay[3] );
}
}
private Name name;
private String suit;
private String cape;
private Date birthDay;
private String power;
public SuperHero(Name name, String suit, String cape, String Power,Date birthDay){
this.name = name;
this.suit = suit;
this.cape = cape;
this.power = power;
this.birthDay = birthDay;
}
public Date getBirthDay(){
return this.birthDay;
}
public Name getName(){
return this.name;
}
public void setSuit (String b){
suit = b;
}
public String getSuit(){
return suit;
}
public void setCape (String t){
cape = t;
}
public String getCape(){
return cape;
}
public void setPower(String v){
power = v;
}
public String getPower(){
return power;
}
}
牛魔王的故事
相关分类