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

The keyword “this” is used to reference a property or a method in a class itself.



2. What is the result of the following PHP code?
    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

__CLASS__ is a magic constants that’s used to display the name of the current class.



3. The child class inherits from _________

A Child class

B Parent class

C Super class

D Base class

B, D
Parent class and Base class are the classes from which the child class inherits.



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’;

Here is the syntax of creating a class constant in PHP: const NAME = ‘VALUE’;



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;

The Operator “::” allow us to access a static, constant, and overridden properties or methods of a class.



6. Which of the following practice is/are not supported by PHP?

A Multiple Inheritance

B Namespaces

C Object Cloning

D Method overloading

A, D
PHP support: Inheritance, Abstract classes, Object cloning, Interfaces, and Namespaces.



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);

You can clone an object by using the clone keyword.



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.

The abstract class is the class in which at least one method need to be abstract. Abstract class is declared with “abstract” keyword.



9. If your object need to inherit behavior from different sources you should use _________

A Abstract class

B Class

C Static class

D Interface

The difference between an interface and a classe is that the class can inherit from one class only while the class can implement one or more interfaces.



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

When we call several methods in one instruction, it is called method chaining. Example:

$p = new Proposal();


mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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