Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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?



How to implement a class named dragonball. This class must have an attribute named ballcount (which ..

Answer / 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

More PHP Interview Questions

How can we get the browser properties using PHP?

7 Answers  


What is advanced php programming?

0 Answers  


What is difference between explode() or split() in PHP?

0 Answers  


Tell me how to find the length of a string?

0 Answers  


What is the difference between php and java?

0 Answers  


What are the types of variables in php?

0 Answers  


what is array_search() in php?

2 Answers  


how to convert PHP code in to java code

4 Answers  


Explain php explode() function.

0 Answers  


What is slim framework?

0 Answers  


How can we submit a form without a submit button?

4 Answers   Agile Software,


When to use single quotes, double quotes, and backticks?

0 Answers  


Categories