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 |
What is include in php?
How can you make a connection with mysql server using php?
Explain how we can retrieve the data in the result set of mysql using php?
Write a query to to delete duplicate rows?
How do you sort an array in php?
How to find out, how a user visited a particular page?
Is gender a dependent variable?
What is a comment in php?
What are different types of Print Functions available in PHP?
How to set session.gc_divisor properly?
Is age interval or ordinal?
How do you destroy a session?