Complete the code to declare a public property in the class.
<?php class Car { [1] $color; } ?>
The public modifier allows the property to be accessed from anywhere.
Complete the code to declare a private method inside the class.
<?php class User { [1] function setPassword($pass) { // code here } } ?>
The private modifier restricts method access to within the class only.
Fix the error in the code by choosing the correct access modifier for the property.
<?php class BankAccount { [1] $balance = 0; public function getBalance() { return $this->balance; } } ?>
The private modifier protects the balance property from being changed directly outside the class.
Fill both blanks to declare a protected property and a public method to access it.
<?php class Employee { [1] $salary; [2] function getSalary() { return $this->salary; } } ?>
The protected property can be accessed within the class and subclasses. The public method allows outside access to the salary.
Fill all three blanks to declare a private property, a protected method, and a public method.
<?php class Document { [1] $content; [2] function editContent($newContent) { $this->content = $newContent; } [3] function readContent() { return $this->content; } } ?>
The private property stores content hidden from outside. The protected method allows editing inside the class or subclasses. The public method allows reading content from anywhere.