PHP Object Oriented Quiz

Last Updated :
Discuss
Comments

Question 1

What is a class in PHP?

  • A

    A function

  • B

    A blueprint for objects

  • C

    A type of variable

  • D

    A database table

Question 2

How do you create an object of a class named Car?

  • A

    $obj = new Car();

  • B

    $obj = Car();

  • C

    new $obj = Car();

  • D

    Car obj = new;

Question 3

What is the purpose of a constructor in PHP classes?

  • A

    To destroy an object

  • B

    To initialize an object

  • C

    To inherit properties

  • D

    To define access modifiers

Question 4

Which magic method acts as a destructor in PHP?

  • A

    __construct()

  • B

    __destruct()

  • C

    __delete()

  • D

    __destroy()

Question 5

What does the public access modifier do?

  • A

    Makes properties accessible only within the class

  • B

    Makes properties accessible within the class and subclasses

  • C

    Makes properties accessible from anywhere

  • D

    Hides properties completely

Question 6

Which modifier restricts property access to the class itself?

  • A

    public

  • B

    protected

  • C

    private

  • D

    static

Question 7

How do you declare a namespace called MyApp?

  • A

    namespace MyApp;

  • B

    use MyApp;

  • C

    package MyApp;

  • D

    module MyApp;

Question 8

What is the purpose of namespaces in PHP?

  • A

    Group related classes and avoid name conflicts

  • B

    Create abstract classes

  • C

    Define constants

  • D

    Manage access modifiers

Question 9

Which keyword is used to include a trait in a class?

  • A

    include

  • B

    use

  • C

    implements

  • D

    extends

Question 10

What is a trait in PHP?

  • A

    A special class type

  • B

    A mechanism for code reuse across unrelated classes

  • C

    A type of interface

  • D

    A namespace alias

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion