Web Designing MCQs

Top 20 MCQ Questions on Classes and Objects in PHP

Google+ Pinterest LinkedIn Tumblr
Here are the collections on top 20 MCQ questions on classes and objects in PHP includes multiple-choice questions on the fundamentals of classes and objects in PHP. It includes MCQ questions on PHP class properties and methods, constructors and destructors in PHP, visibility of a property, scope resolution operator(::) and static keywords.

Read Also: 20 Objective Questions on Arrays in PHP

1. A class may contain its own constants and variables are called …
A) Properties
B) Methods
C) Operators
D) Objects

2. The functions within the class are also called …
A) Properties
B) Methods
C) Operators
D) Objects

3. State whether the following statements are TRUE or FALSE.
i) Class properties and methods live in separate namespaces.
ii) It is possible to have a property and a method with the same name.
iii) Calling an anonymous function that has been assigned to a property is directly possible.
A) i-True, ii-True, iii-True
B) i-True, ii-False, iii-True
C) i-True, ii-True, iii-False
D) i-True, ii-False, iii-False

4. … properties can be accessed and manipulated directly via the corresponding object.
A) Private
B) Public
C) Protected
D) Final

5. … properties are only accessible from within the class in which they are defined.
A) Private
B) Public
C) Protected
D) Final

6. Making a property as … prevents it from being overridden by a subclass.
A) Private
B) Public
C) Protected
D) Final

7. State whether the following statements are TRUE.
i) It is possible to extend multiple classes.
ii) The inherited methods and properties can be overridden by redeclaring them with the same name defined in the parent class.
A) i- only
B) ii- only
C) Both i and ii
D) None of the above

8. Inside the class definition …. refers to the current object.
A) self
B) this
C) $this
D) $current

9. Within the class methods, non-static properties will be accessed using …
A) -> (Object Operator)
B) : (Single Colon)
C) :: (Double Colon)
D) $ (Dollor Sign)

10. Within the class methods, static properties will be accessed using …
A) -> (Object Operator)
B) : (Single Colon)
C) :: (Double Colon)
D) $ (Dollor Sign)

11. The property …. must be an instance of the same class in which the property is defined.
A) self
B) this
C) $this
D) $current

12. The … allows for fully qualified class name resolution at compile time, this is useful for namespaced classes.
A) ->class
B) :class
C) $class
D) ::class

13. The destructor will be called even if script execution is stopped using …
A) stop()
B) pause()
C) remove()
D) exit()

14. Which of the following statements about the OOP constructors are TRUE or FALSE.
i) Constructors can call class methods or other functions.
ii) Class constructors can call on other constructors.
iii) Constructors can accept parameters.
A) i-True, ii-True, iii-True
B) i-True, ii-False, iii-True
C) i-True, ii-True, iii-False
D) i-True, ii-False, iii-False

15. State whether the following statements about the OOP constructors are TRUE or FALSE.
i) PHP also offered class constructors.
ii) PHP automatically calls the parent constructor.
iii) PHP recognizes constructors by the name _construct.
A) i-True, ii-True, iii-True
B) i-True, ii-False, iii-True
C) i-True, ii-True, iii-False
D) i-True, ii-False, iii-False

16. The instanceof keyword was introduced with …
A) PHP 3
B) PHP 4
C) PHP 5
D) PHP 6

17. You can’t use … within a class to refer to a property declared as static.
A) self
B) this
C) $this
D) $current

18. State whether the following statements about the constructors are TRUE.
i) Parent constructors are called implicitly if the child class defines a constructor.
ii) In order to run a parent constructor, a call to parent::_construct() within the child constructor is required.
A) i-True, ii-False
B) i-False, ii-True
C) i-True, ii-False
D) i-False, ii-False

19. … is run when writing data to inaccessible or non-existing properties.
A) _set()
B) _unset()
C) _get()
D) _isset()

20. … is utilized in reading data from inaccessible or non-existing properties.
A) _set()
B) _unset()
C) _get()
D) _isset()

Answers:

  1. A) Properties
  2. B) Methods
  3. C) i-True, ii-True, iii-False
  4. B) Public
  5. A) Private
  6. D) Final
  7. B) ii- only
  8. C) $this
  9. A) -> (Object Operator)
  10. C) :: (Double Colon)
  11. A) self
  12. D) ::class
  13. D) exit()
  14. A) i-True, ii-True, iii-True
  15. B) i-True, ii-False, iii-True
  16. C) PHP 5
  17. C) $this
  18. B) i-False, ii-True
  19. A) _set()
  20. C) _get()

Shuseel Baral is a web programmer and the founder of InfoTechSite has over 8 years of experience in software development, internet, SEO, blogging and marketing digital products and services is passionate about exceeding your expectations.

Write A Comment