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
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
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
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
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
Explanation: To create a new object in PHP we can use the new statement to instantiate a class.
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
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
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
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
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
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.
- Practice MCA MCQs
- Check MCA Books
- Apply for Programming Internship
- Check PHP Books
- Check Information Technology Books