(1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printName, printWeapon方法

package lianxi;

public class XiYouJiRenWu {
    String Name;
    double Height;
    String Weapon;
    
    void printName()
    {
        System.out.println(Name);
    }
    
    void printWeapon()
    {
        System.out.println("武器: "+Weapon);
    }
  
}
    public static void main(String[] args)
    {
        XiYouJiRenWu XiYouJiRenWu1=new XiYouJiRenWu();
        XiYouJiRenWu1.Name="孙悟空";
        XiYouJiRenWu1.Weapon="金箍棒";
        XiYouJiRenWu1.printName();
        XiYouJiRenWu1.printWeapon();
        
        XiYouJiRenWu XiYouJiRenWu2=new XiYouJiRenWu();
        XiYouJiRenWu2.Name="猪八戒";
        XiYouJiRenWu2.Weapon="九齿钉耙";
        XiYouJiRenWu2.printName();
        XiYouJiRenWu2.printWeapon();
            
        
    }

 

posted @ 2016-05-16 14:04  凌零聆  阅读(780)  评论(0编辑  收藏  举报