R4RIN
MCQS
PHP MCQ Quiz Hub
PHP Mcq– Basics of Object-Oriented PHP
Choose a topic to test your knowledge and improve your PHP skills
1. The practice of separating the user from the true inner workings of an application through well-known interfaces is known as _________
Polymorphism
Inheritance
Encapsulation
Abstraction
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?
Abstraction
Polymorphism
Inheritance
Differential
3. The practice of creating objects based on predefined classes is often referred to as ______________
class creation
object creation
object instantiation
class instantiation
4. Which one of the following can be used to instantiate an object in PHP assuming class name to be Foo?
$obj = new $foo;
$obj = new foo;
$obj = new foo ();
obj = new foo ();
5. Which one of the following is the right way to define a constant?
constant PI = “3.1415”;
const $PI = “3.1415”;
constant PI = ‘3.1415’;
const PI = ‘3.1415’;
6. Which one of the following is the right way to call a class constant, given that the class is mathFunction?
echo PI;
echo mathFunction->PI;
echo mathFunction::PI;
echo mathFunction=PI;
7. 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 }
Only ii)
Only iv)
i) and ii)
iii) and iv)
8. . Which of the following method scopes is/are not supported by PHP? i) private ii) friendly iii) static iv) abstract
Only ii)
Only iv)
ii) and iv)
Only i)
9. Which of the following statements is/are true about Constructors in PHP? i) PHP 4 introduced class constructors. ii) Constructors can accept parameters. iii) Constructors can call class methods or other functions. iv) Class constructors can call on other constructors.
ii)
ii) and iii)
i), ii), iii) and iv)
ii), iii) and iv)
10. PHP recognizes constructors by the name _________
classname()
_construct()
function _construct()
function __construct()
11. Which version of PHP introduced the instanceof keyword?
PHP 4
PHP 5
PHP 5.3
PHP 6
12. Which one of the following functions is used to determine whether a class exists?
exist()
exist_class()
class_exist()
__exist()
13. Which one of the following functions is used to determine object type?
obj_type()
type()
is_a()
is_obj()
14. Which one of the following keyword is used to inherit our subclass into a superclass?
extends
implements
inherit
include
15. . In the following PHP code, what is/are the properties? <?php class Example { public $name; function Sample() { echo "This is an example"; } } ?>
echo “This is an example”;
public $name;
class Example
function sample()
16. Which keyword is used to refer to properties or methods within the class itself?
private
public
protected
$this
17. Which of the following advanced OOP features is/are not supported by PHP?
Method overloading
Multiple Inheritance
Namespaces
Object Cloning
18. Which one of the following is the right way to clone an object?
_clone(targetObject);
destinationObject = clone targetObject;
destinationObject = _clone(targetObject);
destinationObject = clone(targetObject);
19. Which of the following is/are true for an abstract class? i) Abstract classes in PHP are declared with the help of abstract keyword. ii) A class is declare abstract by using the keyword implements. iii) It is a class that really isn’t supposed to ever be instantiated but instead serves as a base class. iv) Attempting to instantiate an abstract class results in an error.
Only i)
Only iii)
ii) and iv)
ii), iii) and iv)
20. If one intends to create a model that will be assumed by a number of closely related objects, which class must be used?
Normal class
Static class
Abstract class
Interface
21. Which method is used to tweak an object’s cloning behavior?
clone()
__clone()
_clone
object_clone()
22. Which feature allows us to call more than one method or function of the class in single instruction?
Typecasting
Method Including
Method adding
Method chaining
23. Which magic method is used to implement overloading in PHP?
__call
__invoke
__wakeup
__unset
Submit