Bird
0
0

Which of the following is the correct syntax to declare a class named Book in PHP?

easy📝 Syntax Q3 of 15
PHP - Classes and Objects
Which of the following is the correct syntax to declare a class named Book in PHP?
ABook class {}
Bfunction Book() {}
Cdeclare class Book {}
Dclass Book {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct PHP class syntax

    PHP classes are declared using the keyword class followed by the class name and curly braces.
  2. Step 2: Compare options

    Only class Book {} uses the correct syntax: class Book {}.
  3. Final Answer:

    class Book {} -> Option D
  4. Quick Check:

    Correct class syntax = class Name {} [OK]
Quick Trick: Use 'class ClassName {}' to declare a class [OK]
Common Mistakes:
  • Using 'function' instead of 'class'
  • Writing 'Book class' instead of 'class Book'
  • Adding 'declare' keyword incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes