Questions Answers On Object Oriented PHP
Questions Answers On 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”.
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.
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.
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.
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.
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.
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();
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)