0% found this document useful (0 votes)
128 views

Questions Answers On Object Oriented PHP

This document provides 10 multiple choice questions about object-oriented PHP concepts. The questions cover topics like encapsulation, polymorphism, inheritance, object instantiation, defining constants and methods, and invoking methods. The answers are provided for each question along with a brief explanation.

Uploaded by

Hloni Maduna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Questions Answers On Object Oriented PHP

This document provides 10 multiple choice questions about object-oriented PHP concepts. The questions cover topics like encapsulation, polymorphism, inheritance, object instantiation, defining constants and methods, and invoking methods. The answers are provided for each question along with a brief explanation.

Uploaded by

Hloni Maduna
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PHP Questions & Answers – Basics of Object-Oriented PHP-

1
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Basics of
Object-Oriented PHP”.

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: None.
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: None.
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: None.
4. Which one of the following property scopes is not supported by PHP?
a) friendly
b) final
c) public
d) static
View Answer

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
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: None.
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: None.
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: None;
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 }

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
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) final
iii) static
iv) abstract
a) Only ii)
b) Only iv)
c) ii) and iv)
d) None of the mentioned
View Answer
Answer: d
Explanation: PHP supports six method scopes: public, private, final, static, protected and
abstract.

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
PHP Questions & Answers – Basics of Object-Oriented PHP-
2
This set of PHP Questions and Answers for Experienced people focuses on “Basics of
Object-Oriented PHP- 2”.

1. Which method scope prevents a method from being overridden by a subclass?


a) Abstract
b) Protected
c) Final
d) Static
View Answer
Answer: c
Explanation: None.

2. 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.
a) ii) and iii)
b) All of the mentioned
c) None of the mentioned
d) ii), iii) and iv)
View Answer
Answer: b
Explanation: None.

3. PHP recognizes constructors by the name_________


a) classname()
b) _construct()
c) function _construct()
d) function __construct()
View Answer
Answer: d
Explanation: A double underscore followed by the construct keyword. Its syntax is function
__construct ([ argument1, argument2,…..]) { Class Initialization code }.

4. Which version of PHP introduced the instanceof keyword?


a) PHP 4
b) PHP 5

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
c) PHP 5.3
d) PHP 6
View answer
Answer: b
Explanation: Using instanceof keyword we can determine whether an object is an instance of a
class. $manager = new Employee() … if ($manager instanceof Employee) echo “True”;

5. Which one of the following functions is used to determine whether a class exists?
a) exist()
b) exist_class()
c) class_exist()
d) __exist()
View Answer
Answer: c
Explanation: The class_exist() function returns true or false according to whether the class exists
within the currently executing script content.

6. Which one of the following functions is used to determine object type?


a) obj_type()
b) type()
c) is_a()
d) is_obj()
View Answer
Answer: c
Explanation: The is_a() function returns true if 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.

7. Which one of the following keyword is used to inherit our subclass into a superclass?
a) extends
b) implements
c) inherit
d) include
View Answer
Answer: a
Explanation: None.

8. In the PHP code given below, what is/are the properties?


1. <?php
2. class Example
3. {
4. public $name;

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
5. function Sample()
6. {
7. echo "This is an example";
8. }
9. }
10. ?>
a) echo “This is an example”;
b) public $name;
c) class Example
d) function sample()
View Answer
Answer: b
Explanation: Yes they are nothing but variables.

9. Which keyword is used to refer to properties or methods within the class itself?
a) private
b) public
c) protected
d) $this
View Answer
Answer: d
Explanation: None.

10. Which keyword allows class members (methods and properties) to be used without
needing to instantiate a new instance of the class?
a) protected
b) final
c) static
d) private
View Answer
Answer: c
Explanation: None.

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
PHP Questions & Answers – Advanced Object-Oriented PHP
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Advanced
Object-Oriented PHP”.

1. Which of the following advanced OOP features is/are not supported by PHP?
i) Method overloading
ii) Multiple Inheritance
iii) Namespaces
iv) Object Cloning
a) All of the mentioned
b) None of the mentioned
c) i) and ii)
d) iii) and iv)
View Answer
Answer: c
Explanation: The advanced OOP features are: Object cloning, Inheritance, Interfaces, Abstract
classes, and Namespaces.

2. Which version of PHP introduced the advanced concepts of OOP?


a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
View Answer
Answer: b
Explanation: None.

3. Which one of the following is the right way to clone an object?


a) _clone(targetObject);
b) destinationObject = clone targetObject;
c) destinationObject = _clone(targetObject);
d) destinationObject = clone(targetObject);
View answer
Answer: b
Explanation: You can clone an object by prefacing it with the clone keyword.

4. The class from which the child class inherits is called..


i) Child class

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
ii) Parent class
iii) Super class
iv) Base class
a) Only i)
b) ii), iii) and iv)
c) Only iii)
d) ii) and iv)
View Answer
Answer: d
Explanation: None.

5. Which of the following is/are true for an abstract class?


i) A class is declared abstract by prefacing the definition with the word abstract.
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.
a) Only ii)
b) All of the mentioned
c) ii) and iv)
d) ii), iii) and iv)
View Answer
Answer: a
Explanation: None.

6. If one intends to create a model that will be assumed by a number of closely related
objects, which class must be used?
a) Normal class
b) Static class
c) Abstract class
d) Interface
View Answer
Answer: c
Explanation: None.

7. If your object must inherit behavior from a number of sources you must use a/an
a) Interface
b) Object
c) Abstract class

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
d) Static class
View Answer
Answer: a
Explanation: None.

8. Which method is used to tweak an object’s cloning behavior?


a) clone()
b) __clone()
c) _clone
d) object_clone()
View Answer
Answer: b
Explanation: None.

9. Which feature allows us to call more than one method or function of the class in single
instruction?
a) Typecasting
b) Method Including
c) Method adding
d) Method chaining
View Answer
Answer: d
Explanation: Following is a basic example of method chaining in php: $a = new Order();
$a->CreateOrder()->sendOrderEmail()->createShipment();

10. Which magic method is used to implement overloading in PHP?


a) __call
b) __invoke
c) __wakeup
d) __unset
View Answer
Answer: a
Explanation: None.

This study source was downloaded by 100000790960322 from CourseHero.com on 03-16-2024 13:29:50 GMT -05:00

https://www.coursehero.com/file/171290565/3-Questions-Answers-on-Object-Oriented-PHPdocx/
Powered by TCPDF (www.tcpdf.org)

You might also like