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 |
Does wordpress run on php 7?
Explain mail function in PHP with syntax?
How long is csrf token?
What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
Will a comparison of an integer 12 and a string "13" work in php?
What is "echo" in php?
Explain how to execute a php script using command line.
How do I display php errors?
What does $_cookie means?
What is the salary for php developer(Fresher)?
Tell me what is the definition of a session?
What does csrf token mean?