what is inheritance in php give me an example?
Answer:
Inheritance permits the implementation of additional functionality in similar objects without the need to reimplement all of the shared functionality.
To inherit an another class we have to use extends Keyword
Example:
class phpInterview{
public fuction result(){
echo 'got selected';
}
}
//extending the above class
class questions extends phpInterview{
public function askedQuestions{
echo 'questions mostly from allphpinterviewquestions.blogspot.com ';
}
}
$obj=new questions();
echo $obj-> askedQuestions();
echo $obj->result();
The output is
questions mostly from allphpinterviewquestions.blogspot.com got selected
No comments:
Post a Comment