How to implement a class named dragonball. This class must have an attribute named ballcount (which starts from 0) and a method ifoundaball. When ifoundaball is called, ballcount is increased by one. If the value of ballcount is equal to seven, then the message you can ask your wish is printed, and ballcount is reset to 0. How would you implement this class?
<?php
class Dragonball {
private $ballCount = 0; // starts from 0
public function iFoundaBall() {
$this->ballCount++;
if ($this->ballCount === 7) {
echo "You can ask your wish
";
$this->ballCount = 0; // reset to 0
}
}
}
// Example usage:
$goku = new Dragonball();
for ($i = 0; $i < 10; $i++) {
$goku->iFoundaBall();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
How to specify argument default values?
What is the use session in php?
What is the capacity of mysql database?
How to replace a substring in a given string in php?
Tell me how is the ternary conditional operator used in php?
What is the difference between for and foreach?
what is interface in java.
how to work lamp server
What is static variable in php?
What is the use of friend function?
Explain me what is the importance of "method" attribute in a html form?
Tell me what type of operation is needed when passing values through a form or an url?