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?
Answer Posted / testme
<?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 |
Post New Answer View All Answers
What is the use of nl2br() in php?
What is difference between put and post method in http?
What is the use of count() function in php?
What is the function of trim?
How check submit button is clicked in php?
Tell me what is the definition of a session?
What are the encryption techniques in php?
What are the different filter functions used to filter a variable?
What is the empty function?
What are the two types of variables?
What does php mean?
How php statement is different from php script?
Is runtime polymorphism overriding?
What is the difference between overloading and overriding in php?
What is php7?