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 mysqli php?
What is the use of trim in php?
What is the use of addslashes in php?
Is it worth learning php in 2019?
What are the advantages of triggers in php?
How will you sened requests from server1 to server2 from server2 to server3 and so on .. w/o letting the output come to the browser or say the client end in php
What is the use of 'print' in php?
Whether php supports microsoft sql server?
Tell me how to strip whitespace (or other characters) from the beginning and end of a string?
To find out the current year is leap year or not which date() function we've to use.Give the syntax also
how do we can copy of the content of a web page with the help og the URL and display them onto any other page
What is the use of mvc in php?