1:乌鸡国国王老王在检查唐僧的通关文牒,如果是大唐的通关文牒则盖玉玺,否则盖印章
分析:
类:
乌鸡国国王类:
特征: 姓名(String)、性别(char)、年龄(int)
行为: 检查 --->形参:唐僧类类型 ,返回值类型:void
唐僧类:
特征:姓名(String)、性别(char)、年龄(int)、通关文牒类型(String)
行为:过关乌鸡国 --->形参:空,返回值类型:空
class Tang{
private String name;
private char sex;
private int age;
private String passport;
public void pass(){
System.out.println("过关乌鸡国");
}
public Tang(String name,char sex,int age,String passport){
this.name = name;
this.sex = sex;
this.age = age;
this.passport = passport;
}
}
class King {
private String name;
private char sex;
private int age;
public King(String name,char sex,int age){
this.name = name;
this.sex = sex;
this.age = age;
}
public void check(Tang t){
t.pass();
}
}
public class Test1 {
public static void main(String[] args) {
King king = new King("国王", '男', 52);
Tang t = new Tang("唐僧",'男',43,"大唐");
king.check(t);
}
}