java練習題

學習Java要用心發表於2017-02-20

 

 

/

 
 

 
public class admin {
 String name;
 int shengming;
 public void show() { 
  System.out.println("我是英雄\n我的基本資訊如下:\n姓名:" + name + "\n生命值:" + shengming);
}
}
  
 
public class admin1 {
 String name1;
 int gongji;
 public void show() {
  System.out.println("我是武器\n我的基本資訊如下\n" + "武器名:\n" + name1 + "\n"
    + "攻擊力:\n" + gongji);
 }
}
 
public class admin2 {
 String name2;
 int shengming2;
 String lei;
 public void show() { 
  System.out.println("我是怪物\n我的基本屬性如下:\n" + "姓名:" + name2 + ",生命值:"
    + shengming2 + ",型別:" + lei);
 }
}
 
public class hehe1 {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  admin s = new admin();
  s.name = "孫悟空";
  s.shengming = 9999999;
  s.show();
  admin1 c = new admin1();
  c.name1 = "如意金箍棒";
  c.gongji = 9999999;
  c.show();
  admin2 b = new admin2();
  b.name2 = "玉皇大帝";
  b.shengming2 = 1;
  b.lei = "潛水類";
  b.show();
 }
}
 

相關文章