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
Tell me how is the ternary conditional operator used in php?
What are the new features in php 7?
What are php functions?
How to get the value of current session id?
Where do I run php code?
Why php is used?
Is php class name case sensitive?
Explain what is the difference between mysql_fetch_array() and mysql_fetch_assoc()?
What is mvc in php?
What is list function with their uses.
Write down the code for save an uploaded file using php?
How to return ascii value of character in php?
write a prog using insert,update,delete in this manner as output? name: phno. add button 1.name phno. edit button delete button 2.
> symbol is used to redirect the output of a command. State Whether True or False?
Tell me what is the use of isset() in php?