Bird
0
0

Which of these is the correct way to create an object of class Book?

easy📝 Conceptual Q2 of 15
PHP - Classes and Objects

Which of these is the correct way to create an object of class Book?

A$book = new Book();
B$book = Book();
C$book = create Book();
D$book = Book.new();
Step-by-Step Solution
Solution:
  1. Step 1: Recall PHP object creation syntax

    In PHP, the correct syntax to create an object is using new ClassName();.
  2. Step 2: Check each option

    Only $book = new Book(); follows the correct syntax.
  3. Final Answer:

    $book = new Book(); -> Option A
  4. Quick Check:

    Object creation syntax = new ClassName() [OK]
Quick Trick: Always use new ClassName() to instantiate [OK]
Common Mistakes:
  • Omitting new keyword
  • Using wrong function-like calls
  • Using dot notation for new

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes