public class Person {
private String name;
private Integer age;
private String gender;
public Person() {
}
public Person(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public void ill() {
System.out.println(name + ", " + gender + ", " + age + "岁生病了");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
}
public class Virus {
private String name;
private Integer size;
private String type;
public Virus() {
}
public Virus(String name, int size, String type) {
this.name = name;
this.size = size;
this.type = type;
}
public void attack(Person p) {
System.out.println(name + " 攻击 " + p.getName());
p.ill();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
public class TestVirus {
public static void main(String[] args) {
Virus virus = new Virus("新冠病毒", 10, "冠状病毒");
Person person = new Person("张三 ", 29, "男");
virus.attack(person);
}
}