Reputation: 91
few days ago i was on a job interview, i was asked a question like this one:
There is an abstract class
A
with two methodsfoo
andbar
, from it generated derived classC
, which was implement only the methodfoo
. What changes need to take place in the script, in order to make it work, while the implementation and interface classes A and C should not be changed
abstract class A {
abstract public function foo();
abstract public function bar();
}
class C extends A {
public function foo() {
// some code
}
}
i said: okay we can simple add one method to our C
class
public function bar() {
//
}
they said this is ok, but what if you can't add this method and you can't change abstract class A
(and its methods).
And there are two options, either my interviewer are fool or i am fool and missing something.
I have read php.net
documentation about abstract classes and i do not see any other solution.(ofcourse i can make class A
not abstract or remove abstract modifier
from bar
method but i am not allowed to do that);
Help me please, because this question don't let me sleep!
Upvotes: 0
Views: 76