This set of PHP Multiple Choice Questions & Answers (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
View Answer
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 are used to define an abstract class?
a) extends
b) implements
c) abstract
d) new
View Answer
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();
View Answer
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. At least how many abstract methods must an abstract class contain?
a) None
b) One
c) Two
d) Five
View Answer
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?
a) interface
b) get
c) inherit
d) implements
View Answer
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
View Answer
Explanation: None.
7. Which one of the following methods in the exception class, is used to get a nested exception object?
a) getPrevious()
b) getCode()
c) getFile()
d) getLine()
View Answer
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?
a) throws
b) exception
c) throw
d) final
View Answer
Explanation: The throw keyword is used in conjunction with an Exception object. It halts the 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?
a) stop
b) end
c) break
d) final
View Answer
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 _________
a) overloading
b) overriding
c) overbending
d) overbinding
View Answer
Explanation: None.
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all areas of PHP Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on PHP.
- Check PHP Books
- Practice MCA MCQs
- Apply for Programming Internship
- Check MCA Books
- Practice Programming MCQs