Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP Object Oriented Quiz

Challenge yourself with this PHP Object-Oriented Programming quiz covering key topics like classes, objects, methods, properties, etc.

Last Updated :
Discuss
Comments

Question 1

What is a class in PHP?

  • A function

  • A blueprint for objects

  • A type of variable

  • A database table

Question 2

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

  • $obj = new Car();

  • $obj = Car();

  • new $obj = Car();

  • Car obj = new;

Question 3

What is the purpose of a constructor in PHP classes?

  • To destroy an object

  • To initialize an object

  • To inherit properties

  • To define access modifiers

Question 4

Which magic method acts as a destructor in PHP?

  • __construct()

  • __destruct()

  • __delete()

  • __destroy()

Question 5

What does the public access modifier do?

  • Makes properties accessible only within the class

  • Makes properties accessible within the class and subclasses

  • Makes properties accessible from anywhere

  • Hides properties completely

Question 6

Which modifier restricts property access to the class itself?

  • public

  • protected

  • private

  • static

Question 7

How do you declare a namespace called MyApp?

  • namespace MyApp;

  • use MyApp;

  • package MyApp;

  • module MyApp;

Question 8

What is the purpose of namespaces in PHP?

  • Group related classes and avoid name conflicts

  • Create abstract classes

  • Define constants

  • Manage access modifiers

Question 9

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

  • include

  • use

  • implements

  • extends

Question 10

What is a trait in PHP?

  • A special class type

  • A mechanism for code reuse across unrelated classes

  • A type of interface

  • A namespace alias

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion