OOP PHP – Method Protected

/* protected dapat dipakai agar sebuah method dapat diakses di dalam subclass dimana method tersebut dideklarasikan
 */
<?php
 
class HDiscount {
    protected function disc1($b){
        return $b/10;
    }
    protected function disc2($b){
        return $b/20;
    }
}

class subDiscount extends HDiscount {
    public function discount($b){
        if($b > 2000) {
            return $this->disc1($b);
        } else {
            return $this->disc2($b);
        }
    }
}

$be = new subDiscount();
echo "besarnya discount: " . $be->discount(3000);
?>

Published by

G3n1k

just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s