MCQ

PHP Questions and Answers – Object-Oriented OOP – Part 1

This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Object-Oriented OOP”.
 

1. The concept of separating the user from the internal details of an application is known as_____________

A Abstraction

B Polymorphism

C Inheritance

D Encapsulation

D
In object-oriented PHP encapsulation is a practice of attaching the data members and methods in a single module.

 

 

2. The concept of creating objects based on pre-defined classes is known as_____________

A Class creation

B Class instantiation

C Object creation

D Object instantiation

D
In object-oriented programming, classes are the schemes of PHP objects. Classes do not become objects before instantiation is done. When someone instantiates a class, it creates an instance of it, thus creating the object. In other words, instantiation is the process of creating an instance of an object in memory.

 

 

3. Classes are the ___________ of objects.

A reference

B type

C blueprints

D instances

C
Classes are the blueprints of objects.

 

 

4. Objects are also known as _________.

A reference

B type

C blueprints

D instances

D
We define a class once and then instantiate many objects that belong to them.

 

 

5. Class is a user-defined data type, which includes ______ methods and _______ variable?

A local, global

B global, global

C global, local

D local, local

D
Class is a user-defined data type, which includes local methods and local variable.

 

 

6. How to defin a new class called “MyClass”?

A class MyClass ()

B class MyClass []

C class MyClass {}

D MyClass class{}

C
The class is enclosed using curly braces { } just like functions.

 

 

7. Object are created using _______ keyword?

A object

B create

C new

D obj()

C
Object are created using new keyword.
 
Example:

$obj = new MyClass;

 

 

8. To define a new class you start with the keyword ________ ?

A var

B class

C new

D function

B
To define a new class you start with the keyword “class”.

 

 

9. Constructor is also called ______ function

A automatic

B find

C magic

D key

C
A constructor is also called magic function since, in PHP, magic methods generally start with two underscore __.

 

 

10. Which of the following built-in functions is used to determine object type?

A is_a()

B type()

C obj_type()

D is_obj()

A
The built-in function is_a() returns true if the object belongs to a class type or if it belongs to a class that is a child of that class. Or else false is returned.

 

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 *