[JAVA] Inheritance

Personal notes

Human.java


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

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

    void sleep() {
        System.out.println("sleep");
    }
}

SoccerPlayer.java


public class SoccerPlayer extends Human {

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

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

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

        soccer.walk();
        soccer.sleep();
        soccer.run();
        soccer.kick();
    }
}

Recommended Posts

Inheritance
Inheritance
About inheritance
[Java] Inheritance
Java inheritance
Java inheritance
Advanced inheritance
java (inheritance)
[Java] Class inheritance
About class inheritance.
Ruby Learning # 33 Inheritance
About Ruby inheritance
About java inheritance
Inheritance and interface.
[Java] Overload / Override / Inheritance
Summarize Java inheritance (Java Silver 8)
Notes on multiple inheritance
About inheritance (Java Silver)
Ruby inheritance and delegation
About encapsulation and inheritance
[Java] Implicit inheritance memo
Java learning memo (inheritance)