ADVERTISEMENT
ADVERTISEMENT

PHP OOPs Concept Aptitude Questions and Answers

PHP OOPs Concept Aptitude: This section contains aptitude questions and answers on OOPs Concept.
Submitted by Nidhi, on March 11, 2021

This section contains Aptitude Questions and Answers on PHP OOPs Concept.

1) There are the following statements that are given below, which of them are correct about OOPS in PHP?
  1. OOPS stands for Object-Oriented Programming System.
  2. OOPS provides a clear structure for the program.
  3. OOPS is a programming technique that provides us better management of projects compared to procedural oriented programming.
  4. All of the above

Options:

  1. A and B
  2. A and C
  3. B and C
  4. D

2) What is the full form of OOBS?
  1. Object-Oriented Basic System
  2. Object-Oriented Based System
  3. Object-Oriented Bound System
  4. Object-Oriented Begin System

3) Does PHP support function overloading?
  1. Yes
  2. No

4) Which of the following access specifiers are used in PHP?
  1. private
  2. public
  3. protected
  4. All of the above

5) What is the correct way to create an object of Sample class?
  1. Sample $obj;
  2. Sample $obj = new Sample();
  3. $obj = new Sample()
  4. None of the above

6) By default, member functions of a class are?
  1. private
  2. public

7) Which of the following operator is used to access members of a class using an object?
  1. ->
  2. .

8) What is the correct output of given code snippets in PHP?
<?php
class Sample
{
    public $name;

    function set($n)
    {
        $name = $n;
    }

    function display()
    {
        echo $name;
    }
}

$obj = new Sample();

$obj->set(10);
$obj->display();
?>
  1. 10
  2. Garbage value
  3. Error
  4. None of the above

9) What is the correct output of given code snippets in PHP?
<?php
class Sample
{
    public $name;

    function set($n)
    {
        $this->$name = $n;
    }

    function print ()
    {
        echo $this->$name;
    }
}

$obj = new Sample();

$obj->set(10);
$obj->print();
?>
  1. 10
  2. Garbage value
  3. Error
  4. None of the above

10) What is the correct output of the given code snippets in PHP?
<?php
class Sample
{
    private $name;

    function set($n)
    {
        $this->$name = $n;
    }

    function display()
    {
        echo $this->$name;
    }
}

$obj = new Sample();
$obj->set(10);
$obj->display();
?>
  1. 10
  2. Garbage value
  3. Error
  4. None of the above

11) Which of the following statements are correct about $this in PHP?
  1. The $this object points to the current object of the class.
  2. The $this object can be used inside the class.
  3. We can use $this object outside the class.
  4. All of the above

Options:

  1. A and B
  2. A and C
  3. B and C
  4. D

12) What is the correct output of the given code snippets in PHP?
<?php
class Sample
{
    function fun1()
    {
        echo "fun1 ";
        return $this;
    }

    function fun2()
    {
        echo "fun2 ";
    }
}

$obj = new Sample();

$obj->fun1()
    ->fun2();

?>
  1. fun1
  2. fun2
  3. fun1 fun2
  4. Error

13) What is the correct output of the given code snippets?
<?php
class Sample
{
    function fun1():
        Sample
        {
            echo "fun1 ";
            return $this;
        }

        function fun2()
        {
            echo "fun2 ";
        }
    }

    $obj = new Sample();
    $obj->fun1()
        ->fun2();
?>
  1. fun1
  2. fun2
  3. fun1 fun2
  4. Error

14) Which of the following keyword is used to check a specific object belongs to a specific class?
  1. objectof
  2. instanceof
  3. classof
  4. None of the above

15) What is the correct output of the given code snippets in PHP?
<?php
class Sample
{
    function fun()
    {
        echo "fun1 ";
    }
}

$obj = new Sample();
var_dump($obj instanceof Sample);
?>
  1. bool(true)
  2. bool(false)
  3. Error
  4. None of the above



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.