忍者ブログ

からすまる日誌

20200123 SuperHero.java 他3

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

20200123 SuperHero.java 他3

--->Main431.java
 
public class Main413 {
 public static void main(String[] args) {
  Hero h =new Hero();
  h.run();
  SuperHero sh = new SuperHero();
  sh.run();
 }
}
 
--->Hero.java
 
public class Hero {
 private String name="みなと";
 private int hp =100;
 //attack
 public void attack(Matango m) {
  System.out.println(this.name+"の攻撃");
  m.hp -=5;
  System.out.println("5pのダメージをあたえた");
 }
 //run away
 public void run() {
  System.out.println(this.name+"は逃げ出した");
 }
}
 
--->SuperHero.java
 
public class SuperHero extends Hero{
 private boolean flying;
 public void fly() {
  this.flying=true;
  System.out.println("飛び上がった");
 }
 public void land() {
  this.flying=false;
  System.out.println("着地した");
 }
 public void run() {
  System.out.println("撤退した");
 }
}
 
--->Matango.java
 
public class Matango {
 int hp;
 final int LEVEL = 10;
 char suffix;
 
 void run() {
  System.out.println("お化けキノコ" + this.suffix + "は逃げ出した!");
 }
}
PR

コメント

ブログ内検索

カレンダー

03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30