Php inheritance example

PHOTO EMBED

Wed Aug 25 2021 11:33:31 GMT+0000 (Coordinated Universal Time)

Saved by @dinovas #php

<?php 

Class User {
    protected $name;
    protected $age;

    public function __construct($name,$age){
        $this->name = $name;
        $this->age = $age;
    }
}

class Customer extends User {
    private $balance;

    public function __construct($name,$age,$balance) {
        $this->balance = $balance;
        parent::__construct($name,$age);
    }

    public function getBalance() {
        return $this->balance;
    }

    public function pay($amount) {
        return $this->name . ' paid $'. $amount;
    }
}

$customer1 = new Customer('John',33, 500);

echo $customer1->getBalance();
content_copyCOPY