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 |
Tell me which programming language does php resemble to?
What the limitation of header() function in php?
Explain what are some new features introduced in php7?
Tell me how can we change the maximum size of the files to be uploaded?
How to enable error reporting in php?
What is php session_start() and session_destroy() function?
What is fulltextsearch
What’s the difference between md5(), crc32() and sha1() crypto on PHP? -
What is artisan in php?
What is encapsulation in php?
What are the features of php?
Hi all,, im completely new to PHP, started learning just 2 days before. Can anybody tell me how to run a PHP file to see the program's output? i have created some simple program in Dreamweaver CS3 but don't know how to run it...