PHP Exam Question ( multiple choice )

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."  
LVL 10
honestman31Asked:
Who is Participating?
 
Mohamed AbowardaConnect With a Mentor Software EngineerCommented:
> 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
 
hieloConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.