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?

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


Please Help Members By Posting Answers For Below Questions

Tell me how is the ternary conditional operator used in php?

1046


What are the new features in php 7?

983


What are php functions?

1021


How to get the value of current session id?

946


Where do I run php code?

932


Why php is used?

1085


Is php class name case sensitive?

946


Explain what is the difference between mysql_fetch_array() and mysql_fetch_assoc()?

889


What is mvc in php?

994


What is list function with their uses.

953


Write down the code for save an uploaded file using php?

940


How to return ascii value of character in php?

1137


write a prog using insert,update,delete in this manner as output? name: phno. add button 1.name phno. edit button delete button 2.

1988


> symbol is used to redirect the output of a command. State Whether True or False?

1139


Tell me what is the use of isset() in php?

1054