PHP OOP Problem. Can't Redeclare Class

+1 Kumi Festus · December 8, 2014
The Code is Below
class BankAccount{
    public $balance = 300;
    public $type = "";
    
    public function SetType($input){
       $this->type = $input;
    }
    public function DisplayBalance(){
     return "Balance: ".$this->balance;
    }
    
    public function Deposit($amount){
     $this->balance = $this->balance + $amount;
    }
    
    public function Withdraw($amount){
     if(($this->balance) < $amount){
        echo "Not Enough Funds";
     }else{
       $this->balance = $this->balance - $amount;
     }
    }
  }
 
  class SavingsAccount{
    public $balance = 800;
    
    public function DisplayBalance(){
      return "Balance :"."$". $this->balance;
    }
    
    public function Withdraw($amount){
      if(($this->balance) < $amount){
        echo "Not Enough Funds";
      }else{
       $this->balance = $this->balance - $amount;
      }
    }
    public function Deposit($amount){
      $this->balance = $this->balance + $amount;
    }
  }
 
  class SavingsAccount extends BankAccount{
 
  }
 
   $kumi = new BankAccount;
   $kumi->Deposit(100);
   $kumi->Withdraw(45);
   $kumi->SetType("Super Saver");
   echo $kumi->type. " has " . $kumi->DisplayBalance()."<br/>";
   
   $kumi_savings = new SavingsAccount;
   echo $kumi_savings->DisplayBalance();

I can't see the hitch here
Thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 Ron Butcher · December 8, 2014
You created the class SavingsAccount on line 26.  You cannot create it again.  If you remove the empty class SavingsAccount you created on line 45, then have the SavingsAccount class on line 26 extend BankAccount you will be good to go.
0 Kumi Festus · December 9, 2014
Thanks buddy. I worked. It's good to have some of you guys around to put us right. Jah Bless
  • 1

PHP

103,533 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators