- public class Ch63
- {
- public static void main(String args[])
- {
- Sniperrifle s1=new Sniperrifle("恐懼惡魔",165);
- Sniperrifle s2=new Sniperrifle("狂龍awp",160);
- Sniperrifle s3=new Sniperrifle("m82a1",145);
- Sniperrifle s4=new Sniperrifle("m200",136);
- Machinegun m1=new Machinegun("盤龍RPK",40);
- Machinegun m2=new Machinegun("爆騎",40);
- s1.showProfile();
- s2.showProfile();
- s3.showProfile();
- s4.showProfile();
- m1.showProfile();
- m2.showProfile();
- System.out.println("有"+Sniperrifle.sum+"把狙擊槍和"+ Machinegun.sum+"把機槍!");
- }
- }
- class Sniperrifle
- {
- static int sum=0;
- String name;
- int a;
- Sniperrifle(String n, int a)
- {
- sum++;
- name=n;
- this.a=a;
- }
- void showProfile()
- {
- System.out.println(name+"的傷害為:"+a);
- }
- }
- class Machinegun
- {
- static int sum=0;
- String name;
- int a;
- Machinegun(String n, int a)
- {
- sum++;
- name=n;
- this.a=a;
- }
- void showProfile()
- {
- System.out.println(name+"的傷害為:"+a);
- }
- }
複製代碼 |