Guest User

Untitled

a guest
Sep 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. public class Main {
  2. public static void main(String[] args) {
  3. Hero hero = new Hero("だいぱんまん", 100, 10);
  4. System.out.println(hero.toString()); // -> Hero@7852e922
  5. }
  6. }
  7.  
  8. // toString()をオーバーライドしない場合
  9. class Hero {
  10. private String name;
  11. private int hp;
  12. private int mp;
  13.  
  14. Hero(String name, int hp, int mp) {
  15. this.name = name;
  16. this.hp = hp;
  17. this.mp = mp;
  18. }
  19. }
Add Comment
Please, Sign In to add comment