Abstract class in oops php

 

 

Hi friends . This is very good question for interview context .

Abstract class –  as we know that abstract means , something hidden . So if talk about abstract class . It means something hidden from developer.

This is partial class, it is not having full features of complete class.This class may contains abstract method , which is only declare , not defined . We need to define this method into child class.

We can not create object of abstract class .

Ex-

Abstract class abc {

Public  function set(){

return ‘hiii’;

}

}

$obj = new abc ()

// Fatal error can’t create object

If we define this methods , need to extends the class.

Class def extends abc {

public function test(){

return ‘hi’;

}

}

$obj = new def()

$obj->test();

Note – if we define abstract methods in abstract class then we need define in child class , otherwise it will give error.

Where we use this class —

It is very good question .

Suppose, when multiple programmer work on the same projects then it is better choice , because it is like blank paper sheet , where programmer need to fill this. When we have common task to do , it is better to use this class.

Leave a Reply

Your email address will not be published. Required fields are marked *