For Business
Login
Home
Assessments
Mytat Certificates
Community
Courses
Premium Courses
jobs
Practice
Upskilling
Projects
Help
Run »
balance = $initialBalance; } public function deposit($amount) { $this->balance += $amount; } public function withdraw($amount) { if ($this->balance >= $amount) { $this->balance -= $amount; return $amount; } else { return "Insufficient funds"; } } public function getBalance() { return $this->balance; } } // Creating an instance $account = new BankAccount(1000); // Accessing methods echo "Current Balance: $" . $account->getBalance(); // Output: Current Balance: $1000 $account->deposit(500); echo "
"; echo "After Deposit: $" . $account->getBalance(); // Output: After Deposit: $1500 echo "
"; echo "Withdrawn: $" . $account->withdraw(200); // Output: Withdrawn: $200 echo "
"; echo "Final Balance: $" . $account->getBalance(); // Output: Final Balance: $1300 ?>