Q 1. Which magic method is used to implement overloading in PHP?
A. __call
B. __invoke
C. __wakeup
D. __unset
Show Answer
Answer:-A. __callExplanation
When a class implements __call(), then an object of that class is called with a method that doesn’t exist, __call() is called instead.Q 2. The class from which the child class inherits is called ________
i) Child class
ii) Parent class
iii) Super class
iv) Base class
A. Only i)
B. ii), iii) and iv)
C. Only iii)
D. ii) and iv)
Show Answer
Answer:- D. ii) and iv)Explanation
The class whose properties are inherited by child class is called Base Class or Parent class.Q 3. Which method is used to tweak an object’s cloning behavior?
A. clone()
B. __clone()
C. _clone
D. object_clone()
Show Answer
Answer:-B. __clone()Explanation
A copy of an object is created by using the clone keyword, which calls the object’s __clone() method.Q 4. If your object must inherit behavior from a number of sources you must use a/an
A. Interface
B. Object
C. Abstract class
D. Static class
Show Answer
Answer:-A. InterfaceExplanation
An interface in PHP consists of methods that have no implementations, i.e. the interface methods are abstract methods. The methods in the interfaces must have public visibility scope. The interfaces are different from classes as the class can inherit from one class only whereas the class can implement one or more interfaces.Q 5. Which of the following is/are true for an abstract class?
i) Abstract classes in PHP are declared with the help of abstract keyword.
ii) A class is declare abstract by using the keyword implements.
iii) It is a class that really isn’t supposed to ever be instantiated but instead serves as a base class.
iv) Attempting to instantiate an abstract class results in an error.
A. Only i)
B. Only iii)
C. ii) and iv)
D. ii), iii) and iv)
Show Answer
Answer:-A. Only i)Explanation
The abstract classes are the classes in which at least one method need to be abstract. Abstract classes in PHP are declared with the help of abstract keyword.Q 6. Which one of the following is the right way to clone an object?
A. _clone(targetObject);
B. destinationObject = clone targetObject;
C. destinationObject = _clone(targetObject);
D. destinationObject = clone(targetObject);
Show Answer
Answer:-B. destinationObject = clone targetObject;Explanation
You can clone an object by prefacing it with the clone keyword. A copy of an object is created by using the clone keyword. $copy_of_object = clone $object;Q 7. Which feature allows us to call more than one method or function of the class in single instruction?
A. Typecasting
B. Method Including
C. Method adding
D. Method chaining
Show Answer
Answer:-D. Method chainingExplanation
When many methods are called in a single instruction in PHP, it is called method chaining. Following is a basic example of method chaining in php:Q 8. Which of the following advanced OOP features is/are not supported by PHP?
i) Method overloading
ii) Multiple Inheritance
iii) Namespaces
iv) Object Cloning
A. i)
B. ii)
C. i) and ii)
D. iii) and iv)
Show Answer
Answer:-C. i) and ii)Explanation
The advanced OOP features are: Object cloning, Inheritance, Interfaces, Abstract classes, and Namespaces.Q 9. Which version of PHP introduced the advanced concepts of OOP?
A. PHP 4
B. PHP 5
C. PHP 5.3
D. PHP 6
Show Answer
Answer:-D. PHP 6Explanation
Advanced concepts of OOP were introduced in PHP version 5.Q 10. If one intends to create a model that will be assumed by a number of closely related objects, which class must be used?
A. Normal class
B. Static class
C. Abstract class
D. Interface
Leave a Reply