Challenge: Build a Simple Class
Recap: Building a PHP Class
- Class: Blueprint for objects;
- Properties: Variables that store object data;
- Methods: Functions that define object behavior;
- Constructor: Initializes properties when an object is created.
Use these concepts to complete the exercise below.
Tehtävä
Swipe to start coding
Write a PHP class named Book that models a book with a title and an author. Your class should have:
- Properties to store the title and author.
- A constructor that sets the title and author properties using the provided arguments.
- A method called
displayInfothat outputs the book's title and author in the format:Title: [title], Author: [author].
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 5
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Mahtavaa!
Completion arvosana parantunut arvoon 6.67
Challenge: Build a Simple Class
Pyyhkäise näyttääksesi valikon
Recap: Building a PHP Class
- Class: Blueprint for objects;
- Properties: Variables that store object data;
- Methods: Functions that define object behavior;
- Constructor: Initializes properties when an object is created.
Use these concepts to complete the exercise below.
Tehtävä
Swipe to start coding
Write a PHP class named Book that models a book with a title and an author. Your class should have:
- Properties to store the title and author.
- A constructor that sets the title and author properties using the provided arguments.
- A method called
displayInfothat outputs the book's title and author in the format:Title: [title], Author: [author].
Ratkaisu
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 1. Luku 5
single