PHP Questions and Answers – Object-Oriented OOP – Part 3
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Object-Oriented OOP”.
1. Which keyword is used to reference a property or a method in a class itself?
A Protected
B Public
C Private
D this
2. What is the result of the following PHP code?
<?php class Person { public function __construct(){ echo 'The class "' . __CLASS__ . '" was initiated!'; } } $p = new Person; ?>
A The class __CLASS__ was initiated!
B The class “Person” was initiated!
C The class “p” was initiated!
D Error
3. The child class inherits from _________
A Child class
B Parent class
C Super class
D Base class
4. Which the following is the correct way to define a constant?
A constant AGE = “25”;
B const $AGE = “25”;
C constant AGE = ‘25’;
D const AGE = ‘25’;
5. Assume we have the class Person. Which is the correct way to call a class constant ?
A echo AGE;
B echo Person->AGE;
C echo Person::AGE;
D echo Person=AGE;
6. Which of the following practice is/are not supported by PHP?
A Multiple Inheritance
B Namespaces
C Object Cloning
D Method overloading
7. Which of the following is the correct way to clone an object in PHP?
A _clone(srcObject);
B destObject = clone srcObject;
C destObject = _clone(srcObject);
D destObject = clone(srcObject);
8. Which is/are true for an abstract class?
A Abstract class is declared using the “abstract” keyword.
B Abstract class is declared using the “implements” keyword.
C It is a class that’s not assumed to be instantiated but instead plays as a base class.
D Trying to instantiate an abstract class results in an error.
9. If your object need to inherit behavior from different sources you should use _________
A Abstract class
B Class
C Static class
D Interface
10. Which practice used to call several methods or functions of the class in one instruction?
A Method Including
B Method adding
C Method chaining
D Trait