Modifier | Access outside class? | Access from subclass? |
---|---|---|
public | Yes | Yes |
protected | No | Yes |
private | No | No |
class Person {
protected $firstName, $lastName; private $phone, $email;
// The constructor and the get and set methods are the same // as the Person class
}
class Employee extends Person { private $ssn, $hireDate; // The constructor and the get and set methods are the same as the Employee class // This method uses the protected properties from the Person class public function getFullName() { return $this->lastName . ', ' . $this->firstName; } }