2.按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printNam
XiYouJiRenWu
package com.hanqi.test;
public class XiYouJiRenWu {
String height,name,weapon;
XiYouJiRenWu(String h,String n,String w)
{
height=h;
name=n;
weapon=w;
}
String printName()
{
return name;
}
String printWeapon()
{
return weapon;
}
}
主类
package com.hanqi.test;
public class XiYOuJi {
public static void main(String[] args) {
XiYouJiRenWu m=new XiYouJiRenWu("","猴子","金箍棒");
System.out.println(m.printName());
System.out.println(m.printWeapon());
XiYouJiRenWu p=new XiYouJiRenWu("","猪","耙子");
System.out.println(p.printName());
System.out.println(p.printWeapon());
}
}