PHP Objects MCQs

This section focuses on "Objects" 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. Objects are also known as ______.

A. reference
B. template
C. class
D. instances

View Answer


2. Object are created using ____ keyword?

A. create
B. object
C. new
D. None of the above

View Answer


3. A member function typically accesses members of _____ object only

A. current
B. previous
C. next
D. All of the above

View Answer


4. Constructor is also called ____ function

A. find
B. key
C. automatic
D. magic

View Answer


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

<?php
class letsfindcourse 
{     
    public $lfc_name = "letsfindcourse"; 
      
    
    public function __construct($lfc_name) 
    { 
        $this->lfc_name = $lfc_name; 
    } 
} 


$lfc = new letsfindcourse("letsfindcourse");  
echo $lfc->lfc_name; 

?> 

A. letsfindcourse
B. 1
C. Error
D. No Output

View Answer


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

<?php
   class lfc { 
  
      var $mcq_type; 
     
      function setmcq_type($par){ 
         $this->mcq_type = $par; 
      } 
        
      function getmcq_type(){ 
         echo $this->mcq_type."<br>"; 
      } 
        
   } 
  
  
   $obj = new lfc; 
  
 
   $obj->setmcq_type("Objects Mcq"); 
   $obj->getmcq_type(); 
?> 

A. Objects Mcq
B. Objects Mcq ""
C. Error
D. No Output

View Answer


7. PHP recognizes constructors by the name.

A. classname()
B. _construct()
C. function _construct()
D. function __construct()

View Answer


8. Which one of the following functions is used to determine object type?

A. obj_type()
B. type()
C. is_a()
D. is_obj()

View Answer


9.  Which one of the following can be used to instantiate an object in PHP assuming class name to be LFC?

A. $obj = new $LFC;
B. $obj = new LFC;
C. $obj = new LFC ();
D. obj = new LFC ();

View Answer


10. In the PHP code given below, what is/are the properties?

<?php 
    class letsfindcourse
    {
        public $name;
        function lfc()
        {
            echo "This is an Object Mcq";
        }
    } 
?>

A. echo “This is an Object Mcq”;
B. public $name;
C. class letsfindcourse
D. function lfc()

View Answer





Also check :


Discussion


* You must be logged in to add comment.