Created
May 4, 2014 16:12
-
-
Save Nkzn/9e8e6221a0803d1c4c05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class HelloWorld { | |
| public static void main (String[] args) { | |
| User tom = new User("tom"); | |
| SubUser bob = new SubUser("bob"); | |
| tom.sayHi(); | |
| bob.sayHi(); // オーバーライドしたのでUserと挙動が違うはず | |
| } | |
| } | |
| class User { | |
| String name; | |
| String email; | |
| User(String name) { | |
| this.name = name; | |
| } | |
| void sayHi() { | |
| System.out.println("Hi! I'm " + this.name); | |
| } | |
| } | |
| class SubUser extends User { | |
| SubUser(String name) { | |
| super(name); // User(String name)のコンストラクタを呼び出している | |
| } | |
| @Override | |
| void sayHi() { | |
| System.out.println("HIIII!!! I'm " + this.name); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment