This set of PHP MCQs focuses on “Object Advanced Features – 2”.
1. Which one of the following class can not be instantiated?
a) inherited class
b) abstract class
c) constant class
d) every class
Explanation: An abstract class cannot be instantiated. Instead it defines (and, optionally, partially implements) the interface for any class that might extend it.
2. Which one of the following keywords is used to define an abstract class?
Explanation: The introduction of abstract classes was one of the major changes ushered in with PHP 5. Its inclusion in the list of new features was another sign of PHP’s extended commitment to object-oriented design.
3. Which one of the following is the correct abstract method?
a) public function write()
b) abstract function write()
c) abstract public write();
d) abstract public function write();
Explanation: An abstract method cannot have an implementation. You declare it in the normal way, but end the declaration with a semicolon rather than a method body.
4. Atleast how many abstract methods must an abstract class contain?
Explanation: Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract.
5. Which one of the following keyword is used to implement an interface?
Explanation: A class can implement an interface using the implements keyword in its declaration.
6. Which version of PHP introduced the concept called late static binding?
a) PHP 4
b) PHP 5
c) PHP 5.1
d) PHP 5.3
7. Which one of the following methods in the exception class, is used to get a nested exception object?
Explanation: getCode() – Get the code integer that was passed to the constructor. getFile() – Get the file in which the exception was generated. getLine() – Get the line number at which the exception was generated.
8. Which one of the following keyword is used in conjunction with an Exception object?
Explanation: The throw keyword is used in conjunction with an Exception object. It halts execution of the current method and passes responsibility for handling the error back to the calling code.
9. Which keyword is used to put a stop on inheritance?
Explanation: A final class cannot be subclassed.
10. PHP provides built-in interceptor methods, which can intercept messages sent to undefined methods and properties. This is also known as _________
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice MCQs on all areas of PHP, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.