user4785882
user4785882

Reputation: 91

Abstract class, how to make method abstract

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 methods foo and bar, from it generated derived class C, which was implement only the method foo. 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

Answers (1)

Dinesh Thalke
Dinesh Thalke

Reputation: 176

You Need to declare Class C is Abstract.

Upvotes: 1

Related Questions