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
Is php faster than javascript?
In php how can you jump in to and out of "php mode"?
How does session work in php?
How to upload file in php?
Can you convert php to html?
Do while loops?
How to find current date and time?
What is super () python?
Can php run without apache?
How is it possible to set an infinite execution time for php script?
Explain the difference b/w static and dynamic websites?
What are the encryption functions in php?
What is == and === in php?
> symbol is used to redirect the output of a command. State Whether True or False?
What are examples of dependent variables?