PHP Questions & Answers – Object Advanced Features – 2

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
View Answer

Answer: b
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

Answer: c
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

Answer: d
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.
advertisement
advertisement

4. At least how many abstract methods must an abstract class contain?
a) None
b) One
c) Two
d) Five
View Answer

Answer: b
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

Answer: d
Explanation: A class can implement an interface using the implements keyword in its declaration.
Note: Join free Sanfoundry classes at Telegram or Youtube

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

Answer: d
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

Answer: a
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.
advertisement

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

Answer: c
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

Answer: d
Explanation: A final class cannot be subclassed.
advertisement

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

Answer: a
Explanation: None.

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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.