I am working on a test to maintain my skills and I have a question that I am not 100% sure about.
"Given that we want to run Test::outputTimesFive() the following code snippet has one mistake."
class Test
{
public $_value = 2;
public function __construct()
{
$this->_value = 3;
}
public static function outputTimesFive()
{
echo self::$_value * 5;
}
}
Assuming that I can only point to one line of code with a mistake, of course the line:
public $_value = 2;
because that was what did not allow static method Test::outputTimesFive
to properly work. By adding static
to that variable, I enabled that method to work just fine, but at the same time I've 'killed' the constructor.
In the question we are talking about executing only that static method, no one talks about creating an instance of that object, so what do you think? Was my thinking correct?
The line no. 3 is the correct to point out. The main question is about the static method and we need to do everything to ensure that it will work after correct. Also - I though wrong about constructor, as you guys said - the constructor will anyway work correctly.