Php OOp's interview questions and answers - OneNightStudy.Com

Wednesday, 25 May 2016

Php OOp's interview questions and answers

1. What is difference between this and self in php?

$this is used to refer current object and self is used for current class.
So generally self is used with scope resolution operator to access the static members or the member function of static class.

2.What is static class?

A class is called static class when one of its method or variable is static. We declare the static method or static class by just using keyword static before method or variable. So basic need of static method is that the static method is like constant whose values can be used any where without calling with the object of the class. So static methods can be accessed by the class name.

3.Whay is final keyword is used?
Final keyword is used for methods that we want not to be overridden in the child class.

4. What is abstract class?
Abstract class is the class whose object cannot be created and also it should have atleast one method that is abstract method. In the abstract method only function defination comes. So the class which inherit abstract class declare the abstract method and it is compulsary.

5. Difference between public, private and protected?
Private variables or member functions can be accessed only within the class.
Protected variables or member functions can be accessed with in the class and its child class.
Public variables or member functions can be accessed any where i.e inside, outside and child classes.

6. What is constructor and destructor in PHP?

Constructor is a function defined inside the class and its called by default when class object is defined.
Similary destructor defined inside the class is used to destroy the object and its not needed in php as it is automatically done.

No comments:

Post a Comment