Interview Questions for OPPs

1. What is OOPs?

OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

An Object-Oriented programming (OOP) language will have object-oriented features such as Abstraction, Encapsulation, Inheritance, polymorphism etc.

2.What is Polymorphism?

Polymorphism means create more than one form.  Polymorphism is nothing but assigning behavior or value in a subclass to something that was already declared in the main class. Polymorphism is implemented using the interface pattern in PHP.

There are two methods to implement Polymorphism in php as below.

1. Overloading Method
2. Overriding Method

3.What is Encapsulation?

Encapsulation means total hiding data to prevent unauthorized parties' direct access to data. Encapsulation can be accessed through access modifiers like Public, Private, Protected in php.

4. What is Traits in PHP?

Traits are a mechanism for code reuse in single inheritance languages such as PHP. Multiple traits can be used in a class by listing them in the use statement, separated by commas.

5. What is Type Hinting in PHP?

Type Hinting is used to specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration. When you call the function, PHP will check whether or not the arguments are of the specified type. If not, the run-time will raise an error and execution will be halted.

6. What is Namespaces in PHP?

Namespaces are a way of encapsulating items related classes, interfaces, functions and constants. So we can prevent collision between class names, function names. Namespaces are declared at the beginning of a file using the 'namespace' keyword. A namespace is a hierarchically labeled code block holding a regular PHP code.

Let's see the syntax of declaring namespace as below.

namespace Aryatechno{

}

7. What is Inheritance?

If The sub class will inherit all the public and protected properties and methods from the super class, it is called inheritance. We can inherit class using the extends keyword.

Let's see the syntax of declaring Inheritance as below.

class A{
 
    function methodA{
   }

}
class B extends A {

}

 

Comments

Leave a Reply

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

96217