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

Is empty function c++?

0 Answers  


What is php constructor?

0 Answers  


What is printf in php?

0 Answers  


How can we extract string ‘abc.com ‘ from a string info@abc.com" target="_blank">http://info@abc.com using regular expression of php?

6 Answers  


How many escape sequences are recognized in double-quoted strings?

0 Answers  


What is the use of friend function?

7 Answers   Wipro,


How to assigning a new character in a string using php?

0 Answers  


What is Different between Joomla And Magento?

0 Answers  


Seeking a PHP skilled programmer, with knowledge of MySQL Database, Javascript and AJAX. CSS and HTML is a plus. Temporary job for 2 months. Possibility of extending the contract (depending on how good you are). Location: Delhi. Start: ASAP Contact me at boney@portlane.com together with your CV.

0 Answers   Eniro,


What is delimiter php?

0 Answers  


Is echo a function in php?

0 Answers  


Extract url from this string? It should be flexible for all strings, not for this string only. "yahoo.comyahoo.co.inhotmail.org"

1 Answers   A1 Technology,


Categories