250+ TOP MCQs on PHP Object Advanced Features and Answers

PHP MCQs 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
Answer: b
Clarification: 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
Answer: c
Clarification: 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();
Answer: d
Clarification: 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
Answer: b
Clarification: 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
Answer: d
Clarification: 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
Answer: d
Clarification: 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()
Answer: a
Clarification: 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
Answer: c
Clarification: 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
Answer: d
Clarification: 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
Answer: a
Clarification: None.

To practice MCQs on all areas of PHP,

Leave a Reply

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