Last active
September 5, 2016 04:44
-
-
Save tyoshikawa1106/37c2635b9a56dfab1223f6c93edfc313 to your computer and use it in GitHub Desktop.
オブジェクト指向サンプル - Java
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
package jp.co.bbreak.sokusen._1._8._3; | |
public class Employee { | |
// 社員名 | |
private String name; | |
// 役職 | |
private String position; | |
// 社員名のゲッタ | |
public String getName() { | |
return name; | |
} | |
// 役職のゲッタ | |
public String getPosition() { | |
return position; | |
} | |
// 社員名のセッタ | |
public void setName(String name) { | |
this.name = name; | |
} | |
// 役職のセッタ | |
public void setPosition(String position) { | |
this.position = position; | |
} | |
// 出勤メソッド | |
public void clockIn() { | |
System.out.println(this.name + "出勤しました。"); | |
} | |
// 退勤メソッド | |
public void clockout() { | |
System.out.println(this.name + " 退勤しました。"); | |
} | |
// 仕事メソッド | |
public void work() { | |
System.out.println(this.position + " です。仕事します。"); | |
} | |
} |
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
package jp.co.bbreak.sokusen._1._8._3; | |
public class PartTime extends Employee { | |
// シフト | |
private String shift; | |
// シフトのゲッタ | |
public String getShift() { | |
return shift; | |
} | |
// シフトのセッタ | |
public void setShift(String shift) { | |
this.shift = shift; | |
} | |
// 社員クラスのメソッドをオーバーライド | |
public void work() { | |
System.out.println(getPosition() + "です。シフトの間、仕事します。"); | |
} | |
// 社員クラスのメソッドを呼び出す | |
public void empWork() { | |
super.work(); | |
} | |
} |
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
package jp.co.bbreak.sokusen._1._8._3; | |
public class Company { | |
public static void main(String[] args) { | |
// 社員クラスのインスタンスを生成 | |
Employee emp = new Employee(); | |
// アルバイトクラスのインスタンスを生成 | |
PartTime part = new PartTime(); | |
// 役職名を格納 | |
emp.setPosition("一般社員"); | |
part.setPosition("アルバイト"); | |
// 仕事 | |
emp.work(); | |
part.work(); | |
part.empWork(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment