PHP Class MCQs

PHP Class MCQs : This section focuses on "Class" in PHP. These Multiple Choice Questions (mcq) should be practiced to improve the PHP skills required for various interviews (campus interview, walk-in interview, company interview), placements, entrance exams and other competitive examinations.

1. Classes are the _______ of objects.

A. type
B. blueprints
C. reference
D. instances

View Answer


2. Class is a programmer-defined data type, which includes _____ methods and ______ variable?

A. local, global
B. global, global
C. global, local
D. local, local

View Answer


3. What will be the syntax of defining the class?

A. class lfc ()
B. class lfc []
C. class lfc {}
D. lfc class{}

View Answer


4. We define our own class by starting with the keyword ______ ?

A. class
B. function
C. auto
D. var

View Answer


5. Which of the following is the output of the below code?

<?php 
class letsfindcourse 
{ 
    
    public function __construct(){ 
        echo 'The class "' . __CLASS__ . '" was initiated!<br>'; 
    } 
      
} 
   
$lfc = new letsfindcourse; 
?>

A. The class letsfindcourse was initiated!<br>
B. The class lfc was initiated!<br>
C. Error
D. No Output

View Answer


6. Which of the following is the output of the below code?

<?php 
class letsfindcourse
{ 
    
    public function __destruct(){ 
        echo 'The class "' . __CLASS__ . '" was destroyed!'; 
    } 
      
} 

   
$lfc = new letsfindcourse; 
?>

A. The class letsfindcourse was destroyed!
B. The class lfc was initiated!
C. Error
D. No Output

View Answer


7. 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


8. Which keyword is used to refer to properties or methods within the class itself?

A. Private
B. public
C. Protected
D. this

View Answer


9. Which one of the following is the right way to call a class constant, given that the class is mathFunction?

A. echo mathFunction->PI;
B. echo PI;
C. echo mathFunction::PI;
D. echo mathFunction=PI;

View Answer


10. The class from which the child class inherits is called
(i) Child class
(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





Also check :


Discussion



* You must be logged in to add comment.