PHP Questions and Answers – Object-Oriented OOP – Part 2
This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Object-Oriented OOP”.
1. Which of the following can be used to instantiate an object in PHP supposing class name to be MyClass?
A $obj = new $MyClass;
B $obj = new MyClass;
C $obj = new MyClass();
D obj = new MyClass();
2. In the following source code, what is/are the properties?
<?php class Person { public $name; function showName() { echo "My name is $name"; } } ?>
A echo "My name is $name";
B public $name;
C class Person
D function showName()
3. A member function usually access to members of the _______ object only
A previous
B next
C current
D All of the above
4. What is the result of the following PHP code?
<?php class Person { public $name = "Person"; public function __construct($name) { $this->name = $name; } } $p = new Person("Alex"); echo $p->name; ?>
A Person
B Alex
C Error
D No Output
5. Which is/are the correct way to declare a method?
A function functionName() { function body }
B method methodName() { method body }
C scope function functionName() { function body }
D scope method methodName() { method body }
6. Which of the following scopes is not available in PHP?
A static
B abstract
C friendly
D private
7. Which PHP version provided the “instanceof” keyword?
A PHP 6
B PHP 5.3
C PHP 5
D PHP 4
8. Which of the following built-in functions is used to determine whether a class exists?
A exist_class()
B class_exist()
C exist()
D __exist()
9. Which is the correct way to call a method?
A $object->methodName();
B object->methodName();
C object::methodName();
D $object::methodName();
10. PHP know constructors by the name.
A classname()
B _construct()
C function _construct()
D function __construct()