PHP Multiple Choice Questions – OOPs

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “OOPs”.

1. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
a) Polymorphism
b) Inheritance
c) Encapsulation
d) Abstraction
View Answer

Answer: c
Explanation: In object-oriented PHP encapsulation is a concept of wrapping up or binding up the data members and methods in a single module.

2. Which of the following term originates from the Greek language that means “having multiple forms,” defines OOP’s ability to redefine, a class’s characteristics?
a) Abstraction
b) Polymorphism
c) Inheritance
d) Differential
View Answer

Answer: b
Explanation: The word polymorphism is derived from Greek word poly which means “many” and morphism which means the property which helps us to assign more than one property.

3. The practice of creating objects based on predefined classes is often referred to as ______________
a) class creation
b) object creation
c) object instantiation
d) class instantiation
View Answer

Answer: d
Explanation: In object-oriented programming, classes are the blueprints of php objects. Classes do not actually become objects until 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.

4. Which one of the following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static
View Answer

Answer: a
Explanation: PHP supports five class property scopes: public, private, protected, final and static.

5. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
a) $obj = new $foo;
b) $obj = new foo;
c) $obj = new foo ();
d) obj = new foo ();
View Answer

Answer: c
Explanation: To create a new object in PHP we can use the new statement to instantiate a class.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. Which one of the following is the right way to define a constant?
a) constant PI = “3.1415”;
b) const $PI = “3.1415”;
c) constant PI = ‘3.1415’;
d) const PI = ‘3.1415’;
View Answer

Answer: d
Explanation: Class constants are created like: const NAME = ‘VALUE’;

7. Which one of the following is the right way to call a class constant, given that the class is mathFunction?
a) echo PI;
b) echo mathFunction->PI;
c) echo mathFunction::PI;
d) echo mathFunction=PI;
View Answer

Answer: c
Explanation: The Scope Resolution Operator “::” is a token that allows access to static, constant, and overridden properties or methods of a class.

8. Which one of the following is the right way to invoke a method?
a) $object->methodName();
b) object->methodName();
c) object::methodName();
d) $object::methodName();
View Answer

Answer: a
Explanation: “->” is a dynamic class method invocation in PHP.

9. Which of the following is/are the right way to declare a method?

i) function functionName() { function body }
ii) scope function functionName() { function body }
iii) method methodName() { method body }
iv) scope method methodName() { method body }

a) Only ii)
b) Only iv)
c) i) and ii)
d) iii) and iv)
View Answer

Answer: c
Explanation: In case of public methods, you can forgo explicitly declaring the scope and just declare the method like you would a function.

10. Which of the following method scopes is/are not supported by PHP?

i) private
ii) friendly
iii) static
iv) abstract

a) Only ii)
b) Only iv)
c) ii) and iv)
d) Only i)
View Answer

Answer: a
Explanation: PHP supports six method scopes: public, private, final, static, protected and abstract. But it does not support friendly.

More MCQs on PHP OOPs:

Sanfoundry Global Education & Learning Series – PHP Programming.

To practice all questions on PHP Programming, 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]

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.