-
-
Save AdarshAshwani/0a314523703f939966ed15036fbc7427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Car { | |
private $topSpeed; | |
function __construct($topSpeed) { | |
$this->topSpeed = $topSpeed; | |
} | |
public function drive() { | |
return "Driving at " . $this->topSpeed . " vrooms<br>"; | |
} | |
} | |
$car1 = new Car(120); | |
echo $car1->drive(); | |
// will raise an error if we try to access a private member | |
echo "Top speed for this car is " . $car1->topSpeed; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment