PHP Classes - Multiple Choice Questions

PHP Classes - Multiple Choice Questions


1. A valid class name starts with a ......., followed by any number of letters, numbers, or underscores.

A) Number
B) Letter
C) Period
D) Underscore

2. PHP makes it possible to automatically execute code when a new instance of a class is created, using a special class method called a ........

A) destructor
B) constructor
C) friend
D) initial

3. Once a class has been defined, objects can be created from the class with the ....... keyword.

A) new object
B) construct
C) new
D) both A and C

4. The visibility of a property or method can be defined by prefixing the declaration with the keywords public, protected or private. Class members declared public can be accessed everywhere. Members declared protected can be accessed only within the class itself and by inherited classes. Members declared as private are not accessible.

A) True
B) False

5. All PHP classes come with a default constructor that takes .... arguments.

A) one
B) two
C) three
D) no

6. You access an object’s properties and methods using the ....... operator ( a hyphen followed by a greater than symbol).

A) >>
B) =>
C) ->
D) none of above

7. When you extend a class, the subclass inherits all of the ........ methods from the parent class.

A) Public
B) private
C) protected
D) both A and C

8. The pseudo-variable ...... is available inside any class method when that method is called from within an object context.

A) $construct
B) #this
C) $those
D) $this

9. A class may contain its own .............

A) variables
B) functions
C) constants
D) both A and B
E) all of above

10. Child classes are defined using the keyword .....

A) extends
B) extents
C) child_class
D) extend_class

Answers