?
Solved

PHP Exam Question ( multiple choice )

Posted on 2011-04-26
2
Medium Priority
?
1,716 Views
Last Modified: 2012-05-11
Hello experts , I found this Question in an exam ,
( multiple choice )
Please explain your ANSWER .
You need to keep an eye on the existing number of objects of a given class without introducing a non-class member variable. Which of the following makes this happen?

       a.       Add a member variable that gets incremented in the default constructor and decremented in the destructor  
       b.       Add a local variable that gets incremented in each constructor and decremented in the destructor
       c.       Add a static member variable that gets incremented in each constructor and decremented in the destructor
       d.       This cannot be accomplished since the creation of objects is being done dynamically via "new."  
0
Comment
Question by:honestman31
2 Comments
 
LVL 82

Assisted Solution

by:hielo
hielo earned 800 total points
ID: 35472443
Well, giving you the direct answer would just be a "crime". So here's a hint:

>>without introducing a non-class member variable.
That rules out "b".

So if you know what a member variable and a static variable is, then you would know that it is definitely NOT "d".

So, lookup what is a "member variable" and a "static variable" in Object-Oriented Programming (OOP). You'll know the answer once you look these up.
0
 
LVL 12

Accepted Solution

by:
Mohamed Abowarda earned 1200 total points
ID: 35472579
> existing number of objects of a given class.

The answer is definitely "A".

Since you have number of objects, the variable can't be static, static is variable that let you access it directly from the class without having to create instance (ex: myClass::staticVarName).
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question