封装类作业
1 package com.hanqi.z1p1; 2 3 public class XiYouJiRenWu { 4 5 double Height; 6 String Name; 7 String Weapon; 8 9 void printName() 10 { 11 System.out.println("我的名字是:"+Name); 12 } 13 void pringtWeapon() 14 { 15 System.out.println("我的武器是:"+Weapon); 16 } 17 18 19 20 21 }
1 package com.hanqi.z1p1; 2 3 public class Homework0516 { 4 5 public static void main(String[] args) { 6 // TODO 自动生成的方法存根 7 8 XiYouJiRenWu zhuBaJie=new XiYouJiRenWu(); 9 zhuBaJie.Name="猪八戒"; 10 zhuBaJie.Weapon="九齿钉耙"; 11 zhuBaJie.printName(); 12 zhuBaJie.pringtWeapon(); 13 14 XiYouJiRenWu sunWuKong=new XiYouJiRenWu(); 15 sunWuKong.Name="孙悟空"; 16 sunWuKong.Weapon="金箍棒"; 17 sunWuKong.printName(); 18 sunWuKong.pringtWeapon(); 19 20 21 22 } 23 24 }
运行结果: