LoginSignup
2
1

More than 5 years have passed since last update.

継承

Last updated at Posted at 2017-10-16

自分用メモ

Human.java
public class Human {
    String name;
    int age;
    String country;

    void walk() {
        System.out.println("歩く");
    }

    void sleep() {
        System.out.println("寝る");
    }
}
SoccerPlayer.java
public class SoccerPlayer extends Human {

    void run() {
        System.out.println("走る");
    }

    void kick() {
        System.out.println("蹴る");
    }

    public static void main(String[] args) {
        SoccerPlayer soccer = new SoccerPlayer();

        soccer.walk();
        soccer.sleep();
        soccer.run();
        soccer.kick();
    }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1