Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Hero hero = new Hero("だいぱんまん", 100, 10);
- System.out.println(hero.toString()); // -> Hero@7852e922
- }
- }
- // toString()をオーバーライドしない場合
- class Hero {
- private String name;
- private int hp;
- private int mp;
- Hero(String name, int hp, int mp) {
- this.name = name;
- this.hp = hp;
- this.mp = mp;
- }
- }
Add Comment
Please, Sign In to add comment