fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /*
  6.  * 返り値の型
  7.  */
  8.  
  9. class BaseResultType { }
  10.  
  11. class DerrivedResultType extends BaseResultType { }
  12.  
  13. /*
  14.  * 返り値の型を使う形
  15.  */
  16.  
  17. class BaseUserType {
  18. BaseResultType method() { return new BaseResultType(); }
  19. }
  20.  
  21. class DerrivedUserType extends BaseUserType {
  22. // オーバーライド元から、型を派生先の物へ変更している
  23. @Override
  24. DerrivedResultType method() { return new DerrivedResultType(); }
  25. }
  26.  
  27. class Ideone
  28. {
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. System.out.println((new BaseUserType()).method());
  32.  
  33. System.out.println((new DerrivedUserType()).method());
  34. }
  35. }
Success #stdin #stdout 0.07s 16532KB
stdin
Standard input is empty
stdout
BaseResultType@8efb846
DerrivedResultType@4a574795