Object Oriented Concept(Php ) Questions and Answers

Question 1. You can overwrite a Singleton with the wrong kind of data. 
  1.    TRUE
  2.    FALSE
Explanation:-
Answer: Option B. -> FALSE

Question 2. PHP have not yet supported constructor overloading. 
  1.    TRUE
  2.    FALSE
Explanation:-
Answer: Option A. -> TRUE

Question 3. Which of the following is/are true for an abstract class?
1. A class is declared abstract by prefacing the definition with the word abstract.
2. A class is declare abstract by using the keyword implements.
3. It is a class that really isn’t supposed to ever be instantiated but instead serves as a base class.
4. Attempting to instantiate an abstract class results in an error.
  1.    Only 2
  2.    All of the mentioned
  3.    2 and 4
  4.    2, 3 and 4
Explanation:-
Answer: Option A. -> Only 2

Question 4. Which method is used to tweak an object’s cloning behavior?
  1.    clone()
  2.    __clone()
  3.    _clone
  4.    object_clone()
Explanation:-
Answer: Option B. -> __clone()

Question 5. If one intends to create a model that will be assumed by a number of closely related objects, which class must be used?
  1.    Normal class
  2.    Static class
  3.    Abstract class
  4.    Interface
Explanation:-
Answer: Option C. -> Abstract class

Question 6. Which feature allows us to call more than one method or function of the class in single instruction?
  1.    Typecasting
  2.    Method Including
  3.    Method adding
  4.    Method chaining
Explanation:-
Answer: Option D. -> Method chaining
Following is a basic example of method chaining in php: $a = new Order();
$a->CreateOrder()->sendOrderEmail()->createShipment();

Question 7. If your object must inherit behavior from a number of sources you must use a/an
  1.    Interface
  2.    Object
  3.    Abstract class
  4.    Static class
Explanation:-
Answer: Option A. -> Interface

Question 8. Prior to which version of PHP did constructors took the name of the enclosing class.
  1.    PHP 4
  2.    PHP 5
  3.    PHP 5.3
  4.    PHP 5.4
Explanation:-
Answer: Option B. -> PHP 5
The new unified constructors use the name __construct(). Using the old syntax, a call to a parent constructor would tie you to that particular class: parent::ShopProduct();

Question 9. Inheritance is the means by which one or more classes can be derived from a/an ___ class.
  1.    base
  2.    abstract
  3.    null
  4.    predefined
Explanation:-
Answer: Option A. -> base
A class that inherits from another is said to be a subclass of it. This relationship is often described in terms of parents and children. A child class is derived from and inherits characteristics from the parent.

Question 10. What should be used to refer to a method in the context of a class rather than an object you use?
  1.    ->
  2.    __
  3.    $
  4.    ::
Explanation:-
Answer: Option D. -> ::
Example- parent::__construct()