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:
- A) Properties
- B) Methods
- C) i-True, ii-True, iii-False
- B) Public
- A) Private
- D) Final
- B) ii- only
- C) $this
- A) -> (Object Operator)
- C) :: (Double Colon)
- A) self
- D) ::class
- D) exit()
- A) i-True, ii-True, iii-True
- B) i-True, ii-False, iii-True
- C) PHP 5
- C) $this
- B) i-False, ii-True
- A) _set()
- C) _get()
Read Next: 20 Objective Questions on Classes and Objects in PHP Part-2
1 Comment
Good