There is no problem with the abstract code in the php Manual. what is wrong with the following code?
abstract class A{ abstract public function b(); }class B extends A{ public function b(){ print "ok"; }}$k = new B();
Why does $ k not call the B () method?
There is no problem with the abstract code in the php Manual. where is the above code wrong?
Reply to discussion (solution)
No error
Class B extends {
Public function B (){
Print "OK ";
}
}
Method B is a constructor of Class B. it is automatically executed during instantiation, so OK is output.
No error
Class B extends {
Public function B (){
Print "OK ";
}
}
Method B is a constructor of Class B. it is automatically executed during instantiation, so OK is output.
Will a function with the same letter as the class name be treated as a constructor?
No error
Class B extends {
Public function B (){
Print "OK ";
}
}
Method B is a constructor of Class B. it is automatically executed during instantiation, so OK is output.
Thank you very much.
Yes!
The method with the same name as the class is the constructor.
This is a feature inherited from C ++.
Construct is inherited from Java.
In php, the two methods for declaring constructor coexist.