1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
public class Main { public static void main(String[] args) { p(onlyReturn("こんにちは!")); p(onlyReturn(123)); p(onlyReturn(new Cat(3))); } public static <T> void p(T a) { System.out.println(a); } public static <T> T onlyReturn(T a) { return a; } } abstract class Animal { protected int age; protected Animal(int age) { this.age = age; } abstract String cry(); } class Cat extends Animal { public Cat(int age) { super(age); } @Override public String cry() { return "にゃー(" + this.age + ")"; } @Override public String toString() { return this.cry(); } } |
1 2 3 |
こんにちは! 123 にゃー(3) |