8. วัตถุสิ่งของ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 8-27  ตัวอย่างการใช้ this แทนตัวอ็อบเจกต์ที่ถูกเรียก
public class BankAccount {
  private String id;    // หมายเลขบัญชี 
  private double balance; // ยอดเงินคงเหลือ 
  ...
  public double getBalance() {
    return this.balance;  // คืนยอดเงินของบัญชี “นี้” 
  }
  public void transferTo(BankAccount to, double amt) {
    this.withdraw(amt);   // ถอนเงินจากบัญชี “นี้” 
    to.deposit(amt);      // ฝากเข้าบัญชี to
  }
©2009 S.Prasitjutrakul