Wednesday, June 7, 2017

Interview Questions and Answers - Object Orient Programming in PHP (OOP) - Basics

what is class?


  • Its a blue print (Technical Design/structure) of how methods & behaviors will be written/shown. 

What is an object?


  • Its an instance of a class.

What is the Interface?

  • functionality cannot be provided
  • properties cannot be defined
  • it is to enforce child class to implement all the methods existing in interface is a MUST. 
  • it cannot be instantiated. 
  • methods can only be public inside interface.
  • child class can only implement not extend with interface
  • every method should be abstracted 
  • multiple inheritance is possible with implements keyword
  • multi-level inheritance is possible , that is an interface can extend parent interface and a class can implement child interface and it should implement all the methods from parents interfaces.

Question 4:
What is an Abstract class?


  • functionality can be provided inside it
  • properties can be defined inside it
  • Methods cannot be private, 
  • child class must implement abstract methods
  • child class can extend an abstract class with "extends" keyword instead of "implements" 
  • not every method should be abstract
  • multiple inheritance is not possible

Question 5:
What are properties?


  • information / data/state of an object
Question 6:
What is are Methods?


  • Functions or behaviors of the class
Question 7:
What is Encapsulation?


  • to enclose the properties and behaviors in curly braces so that we don't need to know the information processing inside a class while working with an API calls to this class.
Question 8:
What are Visibility/Access Modifiers?

  • Public - accessible from everywhere
  • Protected - accessible from within class as well child classes
  • private  - accessible from within class ONLY 
Question 9:
What is Static?

  • Method or property available at class level , no object needed
  • changes will affect everywhere in all the instances of the class
Question 10:
What is Constructor?

  • Its a magic method
  • used to initialize the properties of an object 
Question: 11:
What is Polymorphism:

Its a concept that an object can have different forms, means a class can have many child classes which are related to parent class but having different behaviors.


interface Speaking{
     public function speak();

cat implements speaking{
     public function speak(){
           echo 'meeaoo';

dog implements speaking{
     public function speak(){
           echo 'woooah';

person implements speaking{
     public function speak(){
           echo 'lets go';

No comments:

Post a Comment