コード例 #1
0
        $this->model = 'MacBook Pro';
        $this->weight = '3 lbs.';
    }
    function setPassword($password)
    {
        $this->password = $password;
    }
    function getPassword()
    {
        return $this->password;
    }
}
// Create objects from the Classes
$pc = new Computer();
$portable = new Laptop();
$portable->setPassword("letmein2");
$pc->printer = "Lazerboy";
// Direct access okay
$portable->printer = "Daisy";
// echo $pc->userId;     // Error: Can't access directly
echo "<br>My Laptop username is ", $portable->getUserId(), "\n<br>";
echo "My pc username is ", $pc->getUserId(), "\n<br>";
// echo "My pc password is ", $pc->getPassword(), "\n<br>";
echo "My Laptop password is ", $portable->getPassword(), "<br>";
echo "My pc printer is ", $pc->printer, "\n<br>";
echo "My Laptop printer is ", $portable->printer, "<br>";
?>
  </font>
 </body>
</html>