ġ ĳȽĲġ ġ ΂ήΐͿ·Π͈୆଼ġ  ̊᫆ǛƱƓƠƯᲦǪȖǸǧǯȈƷဃ঺ƴƭƍƯ‫ܖ‬፼ƠǇƢŵǇƨᲦᙐૠƷǤȳǹǿȳǹ Ʒဃ঺ƴƭƍƯǋ‫ܖ‬፼ƠǇƢŵ     ଀㗴 ́ ࣭ࣉࣟࢢ࣒ࣛ౛  ࡛సᡂࡋࡓ &XVWRPHU ࢡࣛࢫࡢ㸪࢖ࣥࢫࢱࣥࢫࢆ⏕ᡂࡍࡿࣉࣟࢢࣛ  ࣒ࢆసᡂࡋ࡞ࡉ࠸ࠋ  &XVWRPHUMDYD㸦ࣉࣟࢢ࣒ࣛ౛  ࡛సᡂ῭㸧 
1 class Customer {2int id;3
String name;
4void display() {56
78System.out.println("IDᱻ " + id);
System.out.println("٘౳" + name);}} ࢡࣛࢫᐃ⩏  ࢡࣛࢫྡ  㸸 ([DPSOH  ࣓ࢯࢵࢻྡ 㸸 PDLQ ࣓ࢯࢵࢻ㸫㸫    =ȗȭǰȩȠ̊ ?  ([DPSOHMDYD 
1 class Example221 {2public static void main(String[] args) {3Customer cust = new Customer();4}5 }ታⴕ⚿ᨐ     ࣭ࡇࡢࣉࣟࢢ࣒ࣛࡣ㸪ᐇ⾜ࡋ࡚ࡶ࡞࡟ࡶ⾲♧ࡉࢀࡲࡏࢇࠋ    =˺ಅ৖᪯? ձ (FOLSVH ࡢࠕ-DYDB➨㸰㒊ࠖࣉࣟࢪ࢙ࢡࢺࡢࠕVUFࠖ㝵ᒙ࡟㸪᪂つ -DYD ࢡࣛࢫࢆసᡂࡋ  ࡲࡍࠋ   žૼᙹ ,CXC ǯȩǹſǦǣȳȉǦưλщƢǔ͌ λщ᪮Ⴘࢯ࣮ࢫ࣭ࣇ࢛ࣝࢲ࣮λщ͌-DYDB➨㸰㒊VUF

ྡ๓([DPSOHಟ㣭Ꮚࠕࣃࢵࢣ࣮ࢪࠖ࡟ࢳ࢙ࢵࢡࢆධࢀࡿ࡝ࡢ࣓ࢯࢵࢻ࣭ࢫࢱࣈࢆ ࠕSXEOLFVWDWLFYRLGPDLQ 6WULQJ>@DUJV ࠖసᡂࡋࡲࡍ࠿㸽࡟ࢳ࢙ࢵࢡࢆධࢀࡿͤࡇࢀ௨እࡢ㡯┠࡟ࡣ㸪ධຊࡋࡲࡏࢇࠋ ղ ࣉࣟࢢ࣒ࣛ౛  ࢆཧ⪃࡟ࡋ࡚㸪ࣉࣟࢢ࣒ࣛࢆධຊࡋࡲࡍࠋධຊᚋ㸪(FOLSVH ࡢ     ࣎ࢱࣥࢆᢲࡋ࡚㸪ࣉࣟࢢ࣒ࣛࢆಖᏑࡋࡲࡍࠋ     ࣭ಖᏑᚋ㸪ࠕ࣮ࣟ࢝ࣝኚᩘ FXVW ࡢ್ࡣ౑⏝ࡉࢀ࡚࠸ࡲࡏࢇࠖ࡜࠸࠺㆙࿌࣓ࢵࢭ࣮      ࢪࡀฟࡲࡍࡀ㸪ၥ㢟࠶ࡾࡲࡏࢇࠋ ճ (FOLSVH ࡢ   ࣎ࢱࣥࢆᢲࡋ࡚㸪ࣉࣟࢢ࣒ࣛࢆᐇ⾜ࡋࡲࡍࠋ㸫㸫     ଀㗴 ́ ⸃⺑  ǪȖǸǧǯȈƷဃ঺  Ū Ǥȳǹǿȳǹ҄    ࢡࣛࢫ࠿ࡽ࢜ࣈࢪ࢙ࢡࢺࢆ⏕ᡂࡍࡿࡇ࡜ࢆ㸪࢖ࣥࢫࢱࣥࢫ໬࡜࠸࠸ࡲࡍࠋࡲࡓ㸪ࢡ   ࣛࢫ࠿ࡽ⏕ᡂࡉࢀࡓ࢜ࣈࢪ࢙ࢡࢺࢆ࢖ࣥࢫࢱࣥࢫ࡜࠸࠸ࡲࡍࠋ   Ǥȳǹǿȳǹ҄%WUVQOGTǯȩǹ%WUVQOGTǤȳǹǿȳǹǤȳǹǿȳǹ‫٭‬ૠ ENCUU%WUVQOGT]KPVKF
KF

5VTKPIPCOG XQKFFKURNC[  ]
PCOG
PWNN
 5[UVGOQWVRTKPVNP +&ųᲴ KF ȡǽȃȉ 5[UVGOQWVRTKPVNP ൞ӸᲴ PCOG _FKURNC[ _ǯȩǹƔǒǪȖǸǧǯȈǛဃ঺Ƣǔ ą Ǥȳǹǿȳǹ҄     ࣭ࢡࣛࢫ࡟ᐃ⩏ࡋࡓ࢖ࣥࢫࢱࣥࢫኚᩘࡸ࣓ࢯࢵࢻࡣ㸪࢖ࣥࢫࢱࣥࢫ໬ࡋ࡚ึࡵ࡚      ฼⏝ࡍࡿࡇ࡜ࡀ࡛ࡁࡲࡍࠋ    ࢖ࣥࢫࢱࣥࢫ໬ࡢ࿨௧࡟ࡣ㸪QHZ ࢆ౑࠸ࡲࡍࠋ     グ㏙᪉ἲ㸦࢖ࣥࢫࢱࣥࢫ໬㸧 class ĴŮľ౳ {public static void main(String[] args) {‫ݙة‬Ҿ ‫ݙة‬ொߣ౳ = new ‫ݙة‬Ҿ();}}    QHZ ࡢᚋ࡟ᣦᐃࡋࡓཧ↷ᆺࡢࢡࣛࢫࡀ࢖ࣥࢫࢱࣥࢫ໬ࡉࢀࡲࡍࠋ     ࣭ཧ↷ᆺ࡜ࡣ㸪࢖ࣥࢫࢱࣥࢫࢆཧ↷ࡍࡿኚᩘ࡟ᣦᐃࡍࡿࢹ࣮ࢱᆺ࡛ࡍࠋ     ࣭ཧ↷ᆺ࡟ࡣ㸪సᡂ῭ࡢࢡࣛࢫྡࢆᣦᐃࡋࡲࡍࠋ    ཧ↷ኚᩘ࡟ࡣ㸪࢖ࣥࢫࢱࣥࢫࡢཧ↷ࢆ௦ධࡋࡲࡍࠋ     ࣭ࢥࣥࣆ࣮ࣗࢱࡢෆ㒊࡛ࡣ㸪࢖ࣥࢫࢱࣥࢫࡣ୺グ᠈⿦⨨ୖ࡟グ᠈ࡉࢀࡲࡍࠋ     ࣭ཧ↷࡜ࡣ㸪୺グ᠈⿦⨨ୖࡢ࢖ࣥࢫࢱࣥࢫࡢ఩⨨᝟ሗ㸦࢔ࢻࣞࢫ㸧࡛ࡍࠋ㸫㸫   ࣉࣟࢢ࣒ࣛ౛  ࡛ࡣ㸪࢖ࣥࢫࢱࣥࢫ໬ࡣḟ࡟♧ࡍ㸱⾜┠࡛ࡍࠋ     ([DPSOHMDYD㸦ᢤ⢋㸧 3Customer cust = new Customer();   &XVWRPHU ࢡࣛࢫᆺࡢኚᩘ FXVW ࡟㸪&XVWRPHU ࢡࣛࢫࡢ࢖ࣥࢫࢱࣥࢫࡢཧ↷ࢆ௦ධࡋ࡚  ࠸ࡲࡍࠋ   Ǥȳǹǿȳǹ҄Ʒ්Ǖ%WUVQOGTǯȩǹ
ENCUU%WUVQOGT]KPVKF
ĭǤȳǹǿȳǹƕ
5VTKPIPCOGųဃ঺ƞǕǔXQKFFKURNC[  ]5[UVGOQWVRTKPVNP +&ųᲴ KF 5[UVGOQWVRTKPVNP ൞ӸᲴ PCOG __%WUVQOGTǤȳǹǿȳǹ
ĬǤȳǹǿȳǹ҄ƢǔǤȳǹǿȳǹ‫٭‬ૠKF

PCOGPWNNĮǤȳǹǿȳǹǛųӋༀƢǔȡǽȃȉFKURNC[ Ӌༀ
EWUV%WUVQOGTųᲷPGY%WUVQOGT       ࣭⏕ᡂࡉࢀࡓ࢖ࣥࢫࢱࣥࢫࡢྛ࢖ࣥࢫࢱࣥࢫኚᩘࡣ㸪⮬ືⓗ࡟ึᮇ໬ࡉࢀࡲࡍࠋ     ࣭࢖ࣥࢫࢱࣥࢫ໬ࡢ㝿࡟௦ධࡉࢀࡿึᮇ್ࡣḟࡢ࡜࠾ࡾ࡛ࡍࠋ   Ǥȳǹǿȳǹဃ঺଺Ʒ‫٭‬ૠƷИ஖͌ ȇȸǿ‫׹‬И஖͌ᩚᩘᆺ㸦E\WH㸪VKRUW㸪LQW㸪ORQJ㸧ᾋືᑠᩘⅬᩘᆺ㸦IORDW㸪GRXEOH㸧

ᩥᏐᆺ㸦FKDU㸧?X ┿ഇ್ᆺ㸦ERROHDQ㸧IDOVH

ཧ↷ᆺ㸦6WULQJ ࡞࡝㸧

QXOO㸫㸫  ᙐૠƷǤȳǹǿȳǹƷဃ঺   ୍ࡘࡢࢡࣛࢫ࠿ࡽ㸪」ᩘࡢ࢖ࣥࢫࢱࣥࢫࢆ⏕ᡂࡍࡿࡇ࡜ࡀ࡛ࡁࡲࡍࠋ     グ㏙౛㸦」ᩘࡢ࢖ࣥࢫࢱࣥࢫࡢ⏕ᡂ㸧 //əö಑ĀĩŸľńŸľĀࠅ߻
Customer cust1 = new Customer();//ੴö಑ĀĩŸľńŸľĀࠅ߻
Customer cust2 = new Customer();   ᙐૠƷǤȳǹǿȳǹƷဃ঺ʚƭႸƷǤȳǹǿȳǹƕဃ঺ƞǕǔ%WUVQOGTǯȩǹENCUU%WUVQOGT]KPVKFɟƭႸƷǤȳǹǿȳǹ 5VTKPIPCOGXQKFFKURNC[  ]ƕဃ঺ƞǕǔ
5[UVGOQWVRTKPVNP +&ųᲴ KF 5[UVGOQWVRTKPVNP ൞ӸᲴ PCOG 
__%WUVQOGTǤȳǹǿȳǹ
Ǥȳǹǿȳǹ‫٭‬ૠKF

PCOG

PWNN

ɟƭႸƷǤȳǹǿȳǹ҄ȡǽȃȉӋༀ

FKURNC[ EWUV%WUVQOGTųᲷPGY%WUVQOGT  %WUVQOGTǤȳǹǿȳǹ
Ǥȳǹǿȳǹ‫٭‬ૠKF



PCOG

PWNN

ᢌƏǤȳǹǿȳǹǛӋༀƢǔʚƭႸƷǤȳǹǿȳǹ҄ȡǽȃȉ
FKURNC[ Ӌༀ
EWUV%WUVQOGTųᲷPGY%WUVQOGT       ࣭⏕ᡂࡉࢀࡓ஧ࡘࡢ࢖ࣥࢫࢱࣥࢫࡣ㸪ᛶ㉁ࡢ␗࡞ࡿ஧ࡘࡢ࢜ࣈࢪ࢙ࢡࢺ࡜ࡋ࡚ᢅ      ࠺ࡇ࡜ࡀ࡛ࡁࡲࡍࠋ     ࣭࢖ࣥࢫࢱࣥࢫࢆཧ↷ࡍࡿኚᩘ࡟㸪௚ࡢ࢖ࣥࢫࢱࣥࢫࡢཧ↷ࢆ௦ධࡍࡿ࡜ඖࡢཧ      ↷ࡣᾘ࠼㸪ᚋ࠿ࡽ௦ධࡋࡓཧ↷ࡀṧࡾࡲࡍ㸦ୖ᭩ࡁ㸧ࠋ㸫㸫     ✵⠌໧㗴 ́ ࣭⦎⩦ၥ㢟  ࡛ᐃ⩏ࡋࡓ 3URGXFW ࢡࣛࢫࡢ㸪࢖ࣥࢫࢱࣥࢫࢆ⏕ᡂࡍࡿࣉࣟࢢ࣒ࣛࢆస  ᡂࡋ࡞ࡉ࠸ࠋ  ͤಖᏑᚋ㸪ᩥἲ࢚࣮ࣛ㸦ࢥࣥࣃ࢖࢚࣮ࣝࣛ㸧ࡀ࡞࠸ࡇ࡜ࢆ☜ㄆࡋ࡚ࡃࡔࡉ࠸ࠋ  3URGXFWMDYD㸦⦎⩦ၥ㢟  ࡛ᐃ⩏῭㸧 
1 class Product {2String no;3
String name;4
int price;5
int quantity;
6
void display() {7int total = price * quantity;





8
9
10
11
12
13
14

System.out.println("ŏŸŕ" + no);
System.out.println("ࠊ୥౳ᱻ " + name);
System.out.println("˪͑ᱻ ᱻ " + price + "ʪ");System.out.println("ߣഽᱻ ᱻ " + quantity + "ԡ");System.out.println("֢Ӗ҃͢" + total + "ʪ");}}  ࢡࣛࢫᐃ⩏   ࢡࣛࢫྡ  㸸 3UDFWLFH   ࣓ࢯࢵࢻྡ 㸸 PDLQ ࣓ࢯࢵࢻ
  PDLQ ࣓ࢯࢵࢻࡢฎ⌮᮲௳  ࣭3URGXFW ࢡࣛࢫᆺࡢኚᩘ SUR ࡟㸪3URGXFW ࢡࣛࢫࡢ࢖ࣥࢫࢱࣥࢫࢆ⏕ᡂࡋ࡚ࡑࡢཧ↷   ࢆ௦ධࡋࡲࡍࠋ㸫㸫