Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created September 5, 2016 06:13
Show Gist options
  • Save tyoshikawa1106/f14d3afa24f20267b72885742db3d8e3 to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/f14d3afa24f20267b72885742db3d8e3 to your computer and use it in GitHub Desktop.
Apex abstract サンプル
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();
}
public with sharing class ExManager extends ExEmployee {
/**
* コンストラクタ
*/
public ExManager() {
}
// 返事メソッド
public override void echo() {
System.debug('管理職です。');
}
}
public with sharing class ExPartTime extends ExEmployee {
/**
* コンストラクタ
*/
public ExPartTime() {
}
// 返事メソッド
public override void echo() {
System.debug('アルバイトです。');
}
}
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