返回列表 發帖
  1. public class Ch63
  2. {
  3.     public static void main(String args[])
  4.     {
  5.          Sniperrifle s1=new Sniperrifle("恐懼惡魔",165);
  6.          Sniperrifle s2=new Sniperrifle("狂龍awp",160);
  7.          Sniperrifle s3=new Sniperrifle("m82a1",145);
  8.          Sniperrifle s4=new Sniperrifle("m200",136);
  9.          Machinegun m1=new  Machinegun("盤龍RPK",40);
  10.          Machinegun m2=new  Machinegun("爆騎",40);
  11.          s1.showProfile();
  12.          s2.showProfile();
  13.          s3.showProfile();
  14.          s4.showProfile();

  15.          m1.showProfile();
  16.          m2.showProfile();
  17.          System.out.println("有"+Sniperrifle.sum+"把狙擊槍和"+ Machinegun.sum+"把機槍!");
  18.     }
  19. }
  20. class Sniperrifle
  21. {
  22.     static int sum=0;
  23.     String name;
  24.     int a;


  25.     Sniperrifle(String n, int a)
  26.     {
  27.         sum++;
  28.         name=n;
  29.         this.a=a;
  30.     }
  31.     void showProfile()
  32.     {
  33.         System.out.println(name+"的傷害為:"+a);
  34.     }

  35. }
  36. class Machinegun
  37. {
  38.     static int sum=0;
  39.     String name;
  40.     int a;


  41.     Machinegun(String n, int a)
  42.     {
  43.         sum++;
  44.         name=n;
  45.         this.a=a;
  46.     }
  47.     void showProfile()
  48.     {
  49.         System.out.println(name+"的傷害為:"+a);
  50.     }

  51. }
複製代碼

TOP

返回列表