Complete the code to declare a public property named $name.
<?php class Person { [1] $name; } ?>
private or protected which restrict access.The public keyword makes the property accessible from anywhere.
Complete the code to make the property $age accessible only within the class and its subclasses.
<?php class Person { [1] $age; } ?>
private which restricts access only to the class itself.The protected keyword restricts access to the class itself and its subclasses.
Fix the error in the code by choosing the correct visibility keyword for the property $salary that should be accessible only inside the class.
<?php class Employee { [1] $salary; } ?>
public or protected which allow wider access.The private keyword restricts access to the property only within the class itself.
Fill both blanks to declare a protected property $data and initialize it with an empty array.
<?php class Container { [1] $data = [2]; } ?>
public instead of protected.array() instead of [] (both valid but only one is correct here).The property is declared protected and initialized with an empty array using [].
Fill all three blanks to declare a private property $count, initialize it to zero, and increment it by one inside a method.
<?php class Counter { [1] $count = [2]; public function increment() { $this->count [3] 1; } } ?>
public instead of private.=+ instead of += for increment.The property is declared private, initialized to 0, and incremented using +=.