Created
April 16, 2013 16:36
-
-
Save tksmaru/5397430 to your computer and use it in GitHub Desktop.
適切なインターフェース型が存在しない例のその2
This file contains 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 InterfaceTest { | |
public static void main(String[] args) { | |
// 基底クラスで型を宣言 | |
CoreSysMember member = new Ohta(); | |
//CoreSysMember member = new ItashikiPro(); | |
System.out.println(member.getName()); | |
} | |
/** | |
* コアシスメンバーの基底クラス | |
*/ | |
public static abstract class CoreSysMember { | |
/** | |
* メンバーの名前を取得します。 | |
* @return | |
*/ | |
public abstract String getName(); | |
/** | |
* コアシスは女子禁制なので常にtrueを返します。 | |
* | |
* @return true以外返すことはありません | |
*/ | |
public boolean isMale() { | |
return true; | |
} | |
} | |
/** | |
* コアシスメンバーの実装です | |
*/ | |
public static class Ohta extends CoreSysMember { | |
@Override | |
public String getName() { | |
return "Ohta"; | |
} | |
} | |
/** | |
* コアシスメンバーの別実装です | |
*/ | |
public static class ItashikiPro extends CoreSysMember { | |
@Override | |
public String getName() { | |
return "Itashiki"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment