Dealing with two Classes : Using method from one Class as a parameter to another
Is using a method from one class as a parameter for another class possible?
Example :
Class1 method:
PHP Code:
public void initialA ()
{
if(a<b)
a++;
else
b++;
if(money == 2)
money++;
}
Now making a method for my Class2(Different class file from Class1), is it possible to take ONLY initialA's results of "money++" as one of my parameter, and not take the results of a++ or b++ (assuming these are all int) ?
thanks
Re: Dealing with two Classes : Using method from one Class as a parameter to another
I'm not sure what your question is.
You can not pass a method as a parameter to another method. You can pass a reference to an instance of a class that has the desired method as a parameter in method call.
When you call a method like initialA(), it will execute its statements in the order they are coded. The caller can not specify which statements are to be executed. The initialA() method would have to be specially coded and take a parameter that would tell it what to do.