Created
September 5, 2016 06:13
-
-
Save tyoshikawa1106/f14d3afa24f20267b72885742db3d8e3 to your computer and use it in GitHub Desktop.
Apex abstract サンプル
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 abstract with sharing class ExEmployee { | |
/** | |
* コンストラクタ | |
*/ | |
public ExEmployee() { | |
} | |
private String name; | |
// 名前のゲッタ | |
public String getName() { | |
return name; | |
} | |
// 名前のセッタ | |
public void setName(String name) { | |
this.name = name; | |
} | |
// 返事メソッド | |
public abstract void echo(); | |
} |
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 with sharing class ExManager extends ExEmployee { | |
/** | |
* コンストラクタ | |
*/ | |
public ExManager() { | |
} | |
// 返事メソッド | |
public override void echo() { | |
System.debug('管理職です。'); | |
} | |
} |
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 with sharing class ExPartTime extends ExEmployee { | |
/** | |
* コンストラクタ | |
*/ | |
public ExPartTime() { | |
} | |
// 返事メソッド | |
public override void echo() { | |
System.debug('アルバイトです。'); | |
} | |
} |
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 with sharing class ExMain { | |
/** | |
* コンストラクタ | |
*/ | |
public ExMain() { | |
ExEmployee employee1; | |
ExEmployee employee2; | |
// 1つ目は管理職 | |
employee1 = new ExManager(); | |
// 2つ目はアルバイト | |
employee2 = new ExPartTime(); | |
// 返事メソッドの実行 | |
employee1.echo(); | |
employee2.echo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment